These are used to combine two or more conditions in a statement. They are: AND, OR, NOT and XOR.
\!h Example with AND: all albums with a title that begins with a character greater than C but less than M
SELECT album_name FROM album WHERE
album_name > "C" AND album_name < "M";
\!h Example with OR: a list of all albums that have a title beginning with L, S or P
SELECT album_name FROM album WHERE
album_name LIKE "L%" OR
album_name LIKE "S%" OR
album_name LIKE "P%";
\!h Example with both OR and AND:
SELECT album_name FROM album WHERE
album_name LIKE "L%" OR
album_name LIKE "S%" AND
album_name LIKE "%g"; -- the answers either just begin with L, or they begin with S and end with g
\!h To handle queries containing several boolean conditions, group conditions within parentheses
-- previous example re-written with parentheses for readability:
SELECT album_name FROM album WHERE
album_name LIKE "L%" OR
(album_name LIKE "S%" AND album_name LIKE "%g");
-- forcing a different evaluation order: albums starting with either "L" or "S" and ending with "g"
SELECT album_name FROM album WHERE
(album_name LIKE "S%" OR album_name LIKE "L%") AND
album_name LIKE "%g";
\!h Example with the NOT operator: list of all albums except ones with an album_id of 1 or 3
SELECT * FROM album WHERE NOT (album_id = 1 OR album_id = 3);
-- other ways to write the WHERE clause:
WHERE NOT (album_id = 1) AND NOT (album_id = 3);
WHERE album_id != 1 AND album_id != 3;
WHERE album_id != AND NOT (album_id = 3);
-- Difference between XOR and OR
-- a XOR b is the equivalent to (a AND (NOT b)) OR ((NOT a) AND b)
\!h Example with the XOR operator: find artists whose names end in "es" or start with "The," but not both
SELECT artist_name FROM artist WHERE
artist_name LIKE "The%" XOR
artist_name LIKE "%es";