Skip to main content
Module 2 · Lesson 3 of 47/57 in the course~10 min
Module lessons (3/4)

Renaming with AS

Lesson preview5 hands-on exercises readySQL Course · Module 2 — More Powerful SELECT

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 in snake_case.
  • Use alias for tables (employees AS e) setting the stage for JOIN.
  • Know exactly in which SQL clauses an alias defined in SELECT is 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

  1. 11. Mental Model: Lifecycle of Aliases in the Query
  2. 22. Progressive & Annotated Examples
  3. 33. Interactive Laboratory: When Aliases Are Born
  4. 44. Diagnostic Verification (Quiz)
  5. 55. Progressive Practical Laboratory
Pro Lesson · Module 2 — More Powerful SELECT

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.