Where Filter

SELECT select_list FROM tablo_name WHERE condition ;
SELECT select_list FROM tablo_name WHERE condition ORDER BY
sort_expression;

The SELECT statement returns all rows in one or more columns in a table or view. A WHERE clause is used to select rows that meets a given condition.

The following comparison and logical operators are used to create the WHERE condition.

Operator Description
= Equals
> Greater than
< Less than
>= Greater than or equal to
<= Less than or equal to
< > or != Not equal
AND AND (Logical operator)
OR OR (Logical operator)
IN Returns true if a value matches any value in the list
BETWEEN Returns true if a value is within the specified value range.
LIKE Returns true if a value matches the specified pattern
IS NULL Returns true if the value is NULL, otherwise returns false.
NOT Negates the result of other operators.
SELECT last_name, first_name FROM customer WHERE first_name =
'Jamie' AND last_name = 'Rice';

SELECT first_name, last_name FROM customer WHERE first_name IN
('Ann','Anne','Annie');

Returns rows with the value matching first_name (‘Ann’,’Anne’,’Annie’) and the corresponding last_name values.

SELECT first_name, last_name FROM customer WHERE first_name LIKE
'Ann%' ORDER BY last_name DESC;

Returns the values in the first_name column starting with Ann and the corresponding last_name column and sorts them in descending alphabetical order according to the last_name column.

SELECT first_name, LENGTH(first_name) name_length FROM customer
WHERE first_name LIKE '%Al%' AND LENGTH(first_name) BETWEEN 3
AND 5 ORDER BY name_length ;

The query calculates the length of the values in the first_name column, displays the values with the phrase ‘Al’ in the first_name length between 3 and 5 and sorts them in ascending order according to the first_name length. LIKE ‘%Al%’ filters values that contain ‘Al’.