0
0
SQLquery~10 mins

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

Choose your learning style9 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.