SQL/Filtering & sorting 7 min
Filtering and sorting
WHERE narrows rows, ORDER BY arranges them, LIMIT trims them.
whereorder bylimitnull
WHERE keeps only the rows whose condition is true. You can combine conditions with AND / OR, and match ranges or lists with BETWEEN and IN.
sql · editable
loading editor…
Try it: Change the range so only products under 100 come back.
Text matching uses LIKE, where % stands for any run of characters. Missing values are compared with IS NULL, never with = NULL.
sql · editable
loading editor…
ORDER BY sorts the result (ASC by default, DESC for the reverse) and LIMIT cuts it down to the first N rows — together they answer 'top N' questions.
sql · editable
loading editor…
Try it: Return the three cheapest products instead.
practice this