Restricting and Sorting Rows
Filtering
The WHERE clause keeps rows that satisfy a predicate. Comparison operators include =, <>/!=, >, >=, <, <=. Logical operators combine predicates with precedence NOT, then AND, then OR - parenthesise whenever OR and AND mix.
Range and list tests: BETWEEN a AND b is inclusive of both bounds; IN (list) is shorthand for chained ORs; LIKE uses % for any sequence of characters (including none) and _ for exactly one character, and ESCAPE lets you search for a literal wildcard. NULL is never equal to anything, so = NULL matches nothing; use IS NULL / IS NOT NULL.
Sorting
ORDER BY comes last, supports ASC (default) and DESC per column, and in Oracle places NULLs last for ASC and first for DESC unless you write NULLS FIRST or NULLS LAST. You may sort by a select-list alias, by a column position number, or by a table column not in the select list - except with SELECT DISTINCT, where sort keys must appear in the select list.
Traps
NOT IN with a NULL inside the list returns no rows. LIKE is case-sensitive. String-to-number comparisons rely on implicit conversion and can fail at runtime. Ordering of strings depends on NLS settings.
Worked example
SELECT last_name, salary FROM employees WHERE salary BETWEEN 5000 AND 10000 AND department_id IN (50, 80) ORDER BY salary DESC NULLS LAST, last_name;
Both bounds are included, and the explicit NULLS LAST overrides the DESC default.