SELECT Basics
SELECT is how you get data back out of MySQL, and it is, by a wide margin, the SQL
statement you'll write most often. Every lesson later in this track that talks about filtering,
aggregating, joining, or subquerying is really just adding more pieces onto the same basic shape
you'll learn here: SELECT some columns, FROM a table, optionally
WHERE a condition holds.
Selecting Specific Columns
To pull just a movie's title and release year out of StreamHub's movies table:
SELECT title, release_year
FROM movies;
| title | release_year |
|---|---|
| Signal Lost | 2024 |
| The Last Reel | 2019 |
| Harbor Lights | 2016 |
SELECT * - Every Column
The asterisk is shorthand for "give me every column in the table":
SELECT * FROM movies;
It's convenient while you're exploring data at the command line, but in real application code
it's usually better to name the columns you actually need. Explicit columns make your intent
obvious to anyone reading the query later, and they're immune to breakage if someone adds,
removes, or reorders columns on the table down the line - code that expected a fixed set of
columns in a fixed order can quietly break under SELECT * in ways that naming
columns explicitly never will.
Filtering Rows With WHERE
Add a WHERE clause to only get rows matching a condition:
SELECT * FROM movies
WHERE release_year > 2015;
| id | title | release_year | duration_minutes |
|---|---|---|---|
| 1 | Signal Lost | 2024 | 118 |
| 2 | The Last Reel | 2019 | 102 |
| 3 | Harbor Lights | 2016 | 95 |
Only movies released after 2015 come back - anything older simply never makes it into the
result set. Operators & Conditions, right after
the next couple of lessons, covers every comparison and logical operator you can put in a
WHERE clause in far more depth.
Aliasing With AS
AS renames a column (or a table) in the result set, without changing anything
about the underlying data:
SELECT title AS movie_title
FROM movies;
| movie_title |
|---|
| Signal Lost |
| The Last Reel |
| Harbor Lights |
This becomes especially useful once queries start involving calculated values or joins across several tables - a friendlier column name makes the result far easier for a human, or an application, to read.
DISTINCT - Removing Duplicate Rows
DISTINCT collapses duplicate rows in the result down to one. StreamHub's catalog
has many movies but only a handful of distinct release years among them:
SELECT DISTINCT release_year
FROM movies;
| release_year |
|---|
| 2024 |
| 2019 |
| 2016 |
Without DISTINCT, a year that fifteen different movies share would show up fifteen
times in the result. With it, each distinct value appears exactly once.
Putting It Together: A Realistic StreamHub Query
Here's SELECT, FROM, and WHERE combined into something
you'd genuinely run against StreamHub - finding every 5-star review written by one particular
user:
SELECT movie_id, rating, comment, review_date
FROM reviews
WHERE user_id = 7 AND rating = 5;
| movie_id | rating | comment | review_date |
|---|---|---|---|
| 42 | 5 | Incredible show! | 2026-07-30 |
| 18 | 5 | One of the best I've seen this year. | 2026-05-12 |
Every one of the pieces we covered above - naming columns, filtering with WHERE,
combining conditions - is already visible in this one small query. That's exactly why
SELECT matters so much: it's by far the most-used SQL statement in practice, and
every upcoming lesson on operators, aggregate functions, joins, and subqueries is really just
teaching you new ingredients to drop into this same basic shape.
WHERE clause you just learned matters more there than almost anywhere else in SQL.