SQL AND & OR Statement

The SQL AND & OR statement uses both the AND and OR operators to return records using different conditions . It is usually used together with the WHERE clause.

SQL AND & OR statement

SELECT column_name(s)

FROM table_name

WHERE column_name operator value

AND (column_name operator value OR column_name operator value)


Database Table “Members”

Id FirstName LastName Email City Phone
1 Gilbert Duncan [email protected] Newark 973-600-3300
2 Elvis Daniels [email protected] Piscataway 862-600-3050
3 Michael Green [email protected] Detroit 732-500-5050
4 Kelvin Graham [email protected] Detroit 732-555-5050

SQL AND & OR Example

SELECT *FROM Members

WHERE LastName=’Daniels’

AND (FirstName=’Gilbert’ OR FirstName=’Elvis’)

RESULT of SQL AND & OR statement above will be

Id FirstName LastName Email City Phone
2 Elvis Daniels [email protected] Piscataway 862-600-3050