Pick the Columns You Want
Learn to select specific columns from a table.
You’ve seen how to grab an entire table with SELECT *
. Now let’s get specific. You’ll learn how to ask for just the columns you care about.
Goal
You’ll aim to:
Select specific columns using
SELECT column_name
.Clean up your output.
Tables
Let’s use the following table in this lesson:
The people
table
ID | Name | Age | City |
1 | Aisha | 30 | Karachi |
2 | Dan | 24 | New York |
3 | Fatima | 27 | Lahore |
4 | Lee | 22 | Seoul |
Pick only one column
Let’s say you only want to see the names
from the people
table:
SELECT name FROM people;
You requested only the name column—nothing more.
Awesome! You just pulled a single column from the table!
Select multiple columns
Need more than one column? You can separate them with commas.
SELECT name, city FROM people;
Separate columns with commas rather than *
.
Congratulations! You now know how to customize your results by picking only what matters.
Column order matters
The order you list the columns in your query is the order they’ll appear in your results.
SELECT city, name FROM people;
Order your columns any way you like.
Good! You now know how to handle column order in SQL.
Mini challenge
Select just the type
and name
from the pets
table:
The pets
table
ID | Name | Type | Age |
1 | Coco | dog | 5 |
2 | Luna | cat | 3 |
3 | Goldie | fish | 1 |
Use the above table to write your query:
# Write your query here:
If you’re stuck, click the “Show Solution” button.
Great, you did it! You now know how to query only the parts of the table you need.
Tips
Always separate columns with a comma.
Column names are case-insensitive (but best to match the table).
Keep output readable by selecting only what’s relevant.
What’s next?
You’ve picked what to see—next, let’s choose which rows to see using WHERE
!