select
How do you ask for only the ports above twenty , highest first
SELECT host, port
FROM targets
WHERE port > 21
ORDER BY port DESC;
result
gamma.local 8080
beta.local 443
alpha.local 22
The query ran against the sample table
Order is deterministic because ORDER BY is explicit
WHERE
WHERE filters rows before anything else happens
Use it early
A filter after aggregation is a different clause with a different job
ORDER BY
ASC is the default
DESC reverses it
Add a second key when ties would otherwise come back in an arbitrary order
LIMIT
LIMIT caps the rows returned
It does not make the query cheaper unless the engine can use it with an index
Do not pretend it is a performance fix
Next
Connecting tables in 05 joins
Posted