AND, OR, NOT
Handout
This page needs a recent browser (with SharedArrayBuffer support). Please update Chrome, Edge, Firefox or Safari to the latest version.
Combining conditions
A WHERE clause can test more than one thing at once. Join conditions with:
AND— both must be trueOR— at least one must be trueNOT— flips a condition
SELECT name FROM student WHERE form = '11A' AND score > 88;
This returns 11A students who also scored above 88.
Mixing AND and OR
When you mix AND and OR, use brackets to make the meaning clear, just like in maths:
SELECT name FROM student
WHERE form = '11B' OR score >= 95;
AND is checked before OR, so brackets remove any doubt about what you mean.
Show the name of every student who is in form 11A and scored more than 88.
Click Run to see the output here.
Show the name of every student who is in form 11B or scored 95 or more.
Click Run to see the output here.