⚡ 0 XP
Step 1 of 2
Rename with AS
Column names in a database are often short or technical. AS gives a column a friendly name in the result (an alias):
SELECT name AS player, team AS city FROM players;
The table itself does not change — only the heading in your result. Aliases are very useful later, when you calculate new columns.
ExampleSELECT name AS player,
team AS city
FROM players;
🎯 Challenge: Scoreboard headings +10 XP
For all players, show name renamed to player and runs renamed to total_runs (in that order).
Try twice to unlock the solution (0/2)
query.sqlCtrl ⏎
Tables (practice database)
Results
Press Run to see your query’s rows here.
Checklist
Press Run to check your code.
Lesson notes (text version)
1. Rename with AS
Column names in a database are often short or technical. AS gives a column a friendly name in the result (an alias):
SELECT name AS player, team AS city FROM players;
The table itself does not change — only the heading in your result. Aliases are very useful later, when you calculate new columns.
SELECT name AS player,
team AS city
FROM players;
Challenge: Scoreboard headings
For all players, show name renamed to player and runs renamed to total_runs (in that order).
2. Each value once: DISTINCT
SELECT team FROM players; prints a team once for every player, so Mumbai appears three times. To see each different value only once, add DISTINCT:
SELECT DISTINCT role FROM players;
This answers questions like “which teams are there?” or “which categories does the shop sell?”
SELECT DISTINCT role FROM players;
Challenge: Which teams play?
Show the column team, with each team only once. (There are 5 teams.)