SQL Selecting with more than 1 condition.


Example

The AND keyword is used to add more conditions to the query.

NameAgeGender
Sam18M
John21M
Bob22M
Mary23F
SELECT name FROM persons WHERE gender = 'M' AND age > 20;

This will return:

Name
John
Bob

using OR keyword

SELECT name FROM persons WHERE gender = 'M' OR age < 20;

This will return:

name
Sam
John
Bob

These keywords can be combined to allow for more complex criteria combinations:

SELECT name
FROM persons
WHERE (gender = 'M' AND age < 20)
   OR (gender = 'F' AND age > 20);

This will return:

name
Sam
Mary