Pick columns, filter rows, sort and limit — in SQL and the DataFrame API — without tripping over NULL.
You write SELECT … FROM … WHERE … ORDER BY … LIMIT, but Spark evaluates the clauses in a different logical order: FROM picks the rows, WHERE keeps some of them, SELECT computes the output columns, DISTINCT removes duplicates, ORDER BY sorts and LIMIT cuts. (GROUP BY and HAVING slot in after WHERE — next lesson.)
That order explains rules you'll bump into: an alias defined in SELECT can't be used in WHERE (it doesn't exist yet), but it can be used in ORDER BY.
SELECT order_id, amount * 0.9 AS discounted -- 3. compute columns
FROM orders -- 1. read rows
WHERE status = 'shipped' -- 2. keep some
ORDER BY discounted DESC -- 4. sort (alias OK)
LIMIT 10; -- 5. cutReach the last step for the run summary: the key takeaways from this lesson.