Lesson 3.1
Choosing Columns in a SQL SELECT
A query result is easier to read when it only includes the columns you need.
The SELECT line controls which columns appear in your result. The shortcut * means "show every column", which is useful for exploring a table.
Once you know what you need, name the columns directly. That keeps results focused and makes your query easier for another person to understand.
Pattern
select column_one, column_two
from table_nameSchema · Garden ShopTable · products9 columns · 24 rows
Table · products
9 columns · 24 rowsOne row per product, with price, cost, and inventory levels.
product_id intproduct_name textcategory_id intsupplier_id intprice decimalcost decimalquantity_on_hand intreorder_level intdiscontinued bool
Your task
Show only each product's product name, price, and quantity on hand.
SQL Workbench
⌘↵ to run·
Expected answer
- Columns: product_name, price, quantity_on_hand.
- Rows: 24 products.
Related
Lesson
Your First SQL SELECT Statement
Write a first SELECT and read the returned rows.
Lesson
SQL ORDER BY and LIMIT
Sort rows and keep the focused top results.
Reference
SQL SELECT Syntax
Clause order and the shape of a SELECT query.
Cheatsheet
SQL Query Basics Cheatsheet
SELECT, WHERE, ORDER BY, and LIMIT at a glance.