-- AND (both conditions must be True)SELECT*FROM customersWHERE birthdate > ‘1990-01-01’ AND points >1000-- OR (at least one condition must be True)SELECT*FROM customersWHERE birthdate > ‘1990-01-01’ OR points >1000-- NOT (to negate a condition)SELECT*FROM customersWHERENOT (birthdate > ‘1990-01-01’)
IN Operator
-- Returns customers in any of these states: VA, NY, CASELECT*FROM customersWHEREstateIN (‘VA’, ‘NY’, ‘CA’)
-- Returns customers whose first name starts with bSELECT*FROM customersWHERE first_name LIKE ‘b%’
%: any number of characters
_: exactly one character
REGEXP Operator
-- Returns customers whose first name starts with aSELECT*FROM customersWHERE first_name REGEXP ‘^a’
^: beginning of a string
$: end of a string
|: logical OR
[abc]: match any single characters
[a-d]: any characters from a to d
More Examples
-- Returns customers whose first name ends with EY or ONWHERE first_name REGEXP ‘ey$|on$’-- Returns customers whose first name starts with MY-- or contains SEWHERE first_name REGEXP ‘^my|se’-- Returns customers whose first name contains B followed by-- R or UWHERE first_name REGEXP ‘b[ru]’
IS NULL Operator
-- Returns customers who don’t have a phone numberSELECT*FROM customersWHERE phone ISNULL
ORDER BY Clause
-- Sort customers by state (in ascending order), and then-- by their first name (in descending order)SELECT*FROM customersORDER BYstate, first_name DESC
LIMIT Clause
-- Return only 3 customersSELECT*FROM customersLIMIT3-- Skip 6 customers and return 3SELECT*FROM customersLIMIT6, 3