Bird
Raised Fist0
SQLquery~10 mins

Column aliases with AS in SQL - Step-by-Step Execution

Choose your learning style10 modes available
Concept Flow - Column aliases with AS
Write SELECT statement
↓
Specify column names
↓
Use AS to rename columns
↓
Execute query
↓
Result shows new column names
This flow shows how to rename columns in a query result using AS, making output easier to read.
Execution Sample
SQL
SELECT first_name AS Name, age AS AgeYears FROM users;
This query selects two columns from users and renames them using AS for clearer output.
Execution Table
StepActionInputOutput
1Start query executionSELECT first_name AS Name, age AS AgeYears FROM users;Prepare to read users table
2Read first row from usersRow: {first_name: 'Alice', age: 30}Apply aliases: Name='Alice', AgeYears=30
3Read second row from usersRow: {first_name: 'Bob', age: 25}Apply aliases: Name='Bob', AgeYears=25
4Read third row from usersRow: {first_name: 'Carol', age: 27}Apply aliases: Name='Carol', AgeYears=27
5No more rowsEnd of tableReturn result set with aliased columns
💡 All rows processed, query returns result with columns renamed by AS
Variable Tracker
VariableStartAfter 1After 2After 3Final
NameN/AAliceBobCarolCarol
AgeYearsN/A30252727
Key Moments - 2 Insights
Why do we use AS in the SELECT statement?
AS lets us rename columns in the output for clarity, as shown in execution_table rows 2-4 where original column names become 'Name' and 'AgeYears'.
Does AS change the actual table column names?
No, AS only changes column names in the query result, not in the database table itself, as seen in execution_table step 1 where original columns are read.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, what is the value of 'Name' after reading the second row?
AAlice
BBob
CCarol
D30
💡 Hint
Check execution_table row 3 under Output column for 'Name' value.
At which step does the query finish reading all rows?
AStep 3
BStep 4
CStep 5
DStep 2
💡 Hint
Look for the step mentioning 'No more rows' in execution_table.
If we remove AS and write SELECT first_name, age FROM users, what changes in the output?
AColumn names will be original: first_name and age
BColumn names will be Name and AgeYears
CQuery will fail
DOutput will be empty
💡 Hint
AS is used to rename columns, so removing it keeps original names as per concept_snapshot.
Concept Snapshot
SELECT column_name AS alias_name
Use AS to rename columns in query output.
Aliases improve readability without changing table.
Alias names appear in result headers.
AS keyword is optional but recommended for clarity.
Full Transcript
This lesson shows how to rename columns in SQL query results using the AS keyword. The query selects columns from a table and assigns new names to them for clearer output. The execution steps read each row from the table, apply the aliases, and return the renamed columns. Aliases do not change the actual table columns, only the output headers. This helps make query results easier to understand.

Practice

(1/5)
1. What is the purpose of using AS in an SQL query when selecting columns?
easy
A. To filter rows based on a condition
B. To rename the column in the output result
C. To join two tables together
D. To delete a column from the table

Solution

  1. Step 1: Understand the role of AS in SQL SELECT

    The AS keyword is used to give a temporary name (alias) to a column or expression in the output.
  2. Step 2: Identify what AS does in the query result

    It changes how the column header appears, making the output easier to read or understand.
  3. Final Answer:

    To rename the column in the output result -> Option B
  4. Quick Check:

    Column alias = rename column [OK]
Hint: AS renames columns in output, not data itself [OK]
Common Mistakes:
  • Thinking AS filters rows
  • Confusing AS with JOIN
  • Believing AS deletes columns
2. Which of the following SQL queries correctly uses AS to alias the column price as cost?
easy
A. SELECT price IS cost FROM products;
B. SELECT price TO cost FROM products;
C. SELECT price AS cost FROM products;
D. SELECT price = cost FROM products;

Solution

  1. Step 1: Review correct syntax for column aliasing

    The correct syntax uses AS between the original column name and the alias.
  2. Step 2: Check each option for correct usage

    Only SELECT price AS cost FROM products; uses AS properly: price AS cost. Others use invalid keywords or operators.
  3. Final Answer:

    SELECT price AS cost FROM products; -> Option C
  4. Quick Check:

    Correct alias syntax uses AS [OK]
Hint: Use AS between column and alias name [OK]
Common Mistakes:
  • Using TO instead of AS
  • Using IS or = instead of AS
  • Omitting AS but using invalid syntax
3. Given the table employees with columns first_name and last_name, what will be the output column name of this query?
SELECT first_name AS fname, last_name AS lname FROM employees;
medium
A. fname, lname
B. first_name, last_name
C. first_name AS fname, last_name AS lname
D. fname AS first_name, lname AS last_name

Solution

  1. Step 1: Understand alias effect on output column names

    The AS keyword renames the output columns to the alias names given.
  2. Step 2: Identify the aliases used in the query

    The columns first_name and last_name are aliased as fname and lname respectively.
  3. Final Answer:

    fname, lname -> Option A
  4. Quick Check:

    Aliases become output column names [OK]
Hint: Output columns show alias names, not original names [OK]
Common Mistakes:
  • Expecting original column names in output
  • Confusing alias syntax with output format
  • Thinking AS changes table column names
4. Identify the error in this SQL query:
SELECT product_name AS, price FROM products;
medium
A. No error, query is correct
B. AS keyword should be lowercase
C. Comma should be after AS
D. Missing alias name after AS

Solution

  1. Step 1: Check the syntax of the alias usage

    The AS keyword must be followed by the alias name immediately.
  2. Step 2: Identify the missing alias name

    In the query, product_name AS is incomplete because no alias name is given after AS.
  3. Final Answer:

    Missing alias name after AS -> Option D
  4. Quick Check:

    AS must be followed by alias name [OK]
Hint: AS must always have a name after it [OK]
Common Mistakes:
  • Leaving AS without alias name
  • Thinking AS case matters
  • Misplacing commas around AS
5. You want to display the total sales amount from a sales table with column amount. Which query correctly sums the amounts and shows the result with the column name Total_Sales?
hard
A. All of the above
B. SELECT SUM(amount) Total_Sales FROM sales;
C. SELECT SUM(amount) AS 'Total_Sales' FROM sales;
D. SELECT SUM(amount) AS Total_Sales FROM sales;

Solution

  1. Step 1: Understand aliasing with aggregate functions

    You can alias the result of SUM(amount) using AS or by just placing the alias after the expression.
  2. Step 2: Check each option for correctness

    SELECT SUM(amount) AS Total_Sales FROM sales; uses AS with underscore alias, valid.
    SELECT SUM(amount) Total_Sales FROM sales; omits AS but alias after expression is valid.
    SELECT SUM(amount) AS 'Total_Sales' FROM sales; uses AS with quoted alias, also valid in many SQL dialects.
  3. Step 3: Confirm all options produce correct output

    All options correctly rename the output column to the desired alias.
  4. Final Answer:

    All of the above -> Option A
  5. Quick Check:

    Aliases can use AS, omit AS, or use quotes [OK]
Hint: Aliases can be with AS, without AS, or quoted [OK]
Common Mistakes:
  • Thinking AS is always required
  • Not quoting aliases with spaces
  • Confusing alias with column name
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard