where
Where condition values are essential for filtering and retrieving datas.
Parameters below can be used to the following methods:
findfindOneupdatedeletesoftDeletecountpaginateWhere conditions are flexible you may use it like these:
// Inline
$db->news->find(array('id' => 1));
// Inside where object
$db->news->find(
array(
'where' => array(
'id' => 1
)
)
);Using Primary ID:
Example:
Using other columns:
Example:
Complex Conditions:
This scopes the equal, like, greater than, greater than or equal, etc.
equal (=)
SELECT * FROM news WHERE id = 1
in ( IN (....) )
SELECT * FROM news WHERE id in (1, 2, 3)
gt ( > $ )
SELECT * FROM news WHERE id > 5
gte ( >= $ )
SELECT * FROM news WHERE id >= 5
lt ( < $ )
SELECT * FROM news WHERE id < 5
lte ( <= $ )
SELECT * FROM news WHERE id <= 5
like ( LIKE '%$%' )
SELECT * FROM news WHERE name like '%test%'
between ( BETWEEN $ and $ )
SELECT * FROM news WHERE created_at between '2024-01-01' and '2024-12-31'
How about the or's and the and's ?
or
SELECT * FROM news WHERE name like '%your test%' or name = 'my test'
and
SELECT * FROM news WHERE id ≥ 1 and id <= 20
not_null
SELECT * FROM news WHERE name IS NOT NULL
null
SELECT * FROM news WHERE name NULL
Combining Conditions
SELECT * FROM news
WHERE name like '%your test%' and name = 'my test'
and created_at between 'date1' and 'date2'
Last updated