← CodePrimer
SQL
Beginner
Database
WHERE with AND / OR
How do I combine filters in SQL?
AND / OR precedence.
SELECT id, name, year_level
FROM students
WHERE year_level = 1
AND (course = 'web1' OR course = 'web2')
ORDER BY name;
Notes
Use parentheses when mixing AND and OR.
Keywords: where · and · or · filter
Related
SQL
CREATE DATABASE
How do I create a MySQL database?
SQL
ALTER TABLE add column
How do I add a column to an existing table?
SQL
Foreign key relationship
How do I relate posts to users?
SQL
COUNT with GROUP BY
How do I count rows per category?
SQL
LIKE search pattern
How do I search text with a keyword?
SQL
Basic transaction
How do I commit or roll back multiple writes?