Your First SQL SELECT Statement
A SELECT query chooses columns from a table and returns a result.
The first SQL pattern to learn is
SELECT
plus
FROM.
SELECT
says which columns you want, and
FROM
says which table to read.
LIMIT
is useful while learning because it keeps the result small. Which rows count
as "first" is up to the database until you sort them, which Lesson 1.6
covers.
select column_one, column_two
from table_name
limit 5 When to use SELECT
Use
SELECT
when you want to inspect data without changing it. A good first query asks
for a few named columns from one table, then limits the result so you can
check the shape before adding filters, joins, or calculations.
Avoid starting every query with
select *. It is useful for quick exploration, but named columns make the result
easier to read, make dependencies explicit, and avoid unexpectedly pulling
newly added columns into downstream results.
Schema · Garden Shop Table · products 9 columns · 24 rows
One row per product, with price, cost, and inventory levels.
Show each product's product name and price. Keep the result to the first 5 rows.
Run your query to inspect the result.
Expected answer
- Columns: product_name, price.
- Rows: 5 products.
Related
Clause order and the shape of a SELECT query.
SELECT, WHERE, ORDER BY, and LIMIT at a glance.
Sort before you limit, or top-N is arbitrary.
WHERE is evaluated before SELECT aliases exist.
The parser stopped at the first word it could not use.
No table in the FROM clause has that column.