Module lessons (3/4)
Renaming with AS
Give clearer column and expression aliases in your result set.
What you'll learn in this lesson
- Rename columns and calculated expressions in the result with
AS <alias>following clear conventions insnake_case. - Use alias for tables (
employees AS e) setting the stage forJOIN. - Know exactly in which SQL clauses an alias defined in
SELECTis visible (ORDER BY) and where does not yet exist (WHERE).
Overview
When a query evaluates expressions (salary * 13, first_name || ' ' || last_name, AVG(salary)), the database assigns unclear anonymous names such as ?column? or avg. With AS choose a readable and self-explanatory name for your result-set or API.
Scroll through the WHERE vs HAVING scenario step by step: observe at step SELECT the appearance of the calculated alias avg_sal and check why WHERE cannot see it while ORDER BY uses it without problems:
Sections covered in this lesson
- 11. Mental Model: Lifecycle of Aliases in the Query
- 22. Progressive & Annotated Examples
- 33. Interactive Laboratory: When Aliases Are Born
- 44. Diagnostic Verification (Quiz)
- 55. Progressive Practical Laboratory
Unlock "Renaming with AS" and the full SQL Course curriculum
Give clearer column and expression aliases in your result set.
Unlock all 5 hands-on exercises in this lesson plus every advanced WebAssembly module with automated checks.
- Instant access to all advanced modules in SQL Course plus 17 more courses
- Hands-on browser exercises with automated test suites and solutions
- 14-day money-back guarantee processed via Paddle.com
14-day guarantee · Cancel anytimeModule 1, all 18 interactive games, and cheatsheets are always free.