0
0
SQLquery~10 mins

SELECT specific columns in SQL - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - SELECT specific columns
Start Query
Parse SELECT clause
Identify columns to retrieve
Scan table rows
Extract specified columns from each row
Return result set with selected columns
End Query
The query starts by reading which columns to select, then scans the table rows, extracts only those columns, and returns them as the result.
Execution Sample
SQL
SELECT name, age FROM users;
This query retrieves only the 'name' and 'age' columns from every row in the 'users' table.
Execution Table
StepActionCurrent Row DataColumns ExtractedResult Set So Far
1Start query executionN/AN/A[]
2Read first row{id:1, name:'Alice', age:30, city:'NY'}name, age[{name:'Alice', age:30}]
3Read second row{id:2, name:'Bob', age:25, city:'LA'}name, age[{name:'Alice', age:30}, {name:'Bob', age:25}]
4Read third row{id:3, name:'Carol', age:27, city:'Chicago'}name, age[{name:'Alice', age:30}, {name:'Bob', age:25}, {name:'Carol', age:27}]
5No more rowsN/AN/A[{name:'Alice', age:30}, {name:'Bob', age:25}, {name:'Carol', age:27}]
💡 All rows processed, query returns result set with only 'name' and 'age' columns.
Variable Tracker
VariableStartAfter Row 1After Row 2After Row 3Final
result_set[][{name:'Alice', age:30}][{name:'Alice', age:30}, {name:'Bob', age:25}][{name:'Alice', age:30}, {name:'Bob', age:25}, {name:'Carol', age:27}][{name:'Alice', age:30}, {name:'Bob', age:25}, {name:'Carol', age:27}]
Key Moments - 2 Insights
Why does the result only include 'name' and 'age' and not other columns like 'id' or 'city'?
Because the SELECT clause specifies only 'name' and 'age' columns, the query extracts only these columns from each row as shown in execution_table rows 2-4.
What happens if the table has more rows than shown?
The query continues scanning each row, extracting only the specified columns, and appends them to the result set until no rows remain, as indicated in execution_table row 5.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what columns are extracted from the second row?
Aid, name
Bname, age
Cage, city
Did, city
💡 Hint
Check the 'Columns Extracted' column in execution_table row 3.
At which step does the query finish reading all rows?
AStep 5
BStep 4
CStep 3
DStep 2
💡 Hint
Look for the step where 'No more rows' is indicated in the 'Action' column.
If we add 'city' to the SELECT clause, how would the 'Columns Extracted' change at step 2?
Aid, city
Bname, age
Cname, age, city
Did, name, age
💡 Hint
Adding 'city' means it will be included in the extracted columns for each row.
Concept Snapshot
SELECT specific columns syntax:
SELECT column1, column2 FROM table_name;

- Retrieves only listed columns from all rows.
- Result set contains fewer columns than the full table.
- Useful to get just needed data, improving clarity and performance.
Full Transcript
This visual execution trace shows how a SQL query with SELECT specific columns works. The query starts by reading which columns to select, then scans each row in the table. For each row, it extracts only the specified columns and adds them to the result set. This continues until all rows are processed. The final output contains only the chosen columns for every row. This helps to get just the data you want from a table without extra information.