Welcome to your first SQL lesson! To retrieve data from a SQL database, we use SELECT
statements, which are commonly referred to as queries. A query is simply a request that tells the database what data we need, where to find it, and optionally, how to process it before returning the results.
Think of a query as asking a question to your database: "Show me all the customer names" or "What are the top 5 highest-selling products?" The database then responds with the exact information you requested.
Before we write our first query, let's understand how data is organized in SQL databases.
You can think of a SQL table as representing a type of entity. For example:
Dogs
could store information about different breeds of dogsMovies
could store information about filmsCustomers
could store information about your business customersTable structure:
The simplest query we can write is one that selects specific columns from a table while including all rows. This allows us to retrieve only the information we need without pulling unnecessary data.
SELECT column_name, another_column
FROM table_1;
This query extracts only the specified columns from table_1
and returns the data as a structured result with rows and columns.
Example:
SELECT title, director
FROM movies;
This would return just the movie titles and directors, without other information like release year, budget, or ratings.
If you want to retrieve all columns from a table without listing each one individually, you can use the *
wildcard:
SELECT *
FROM table_1;
This query returns every column and row from the table, making it a quick way to inspect data.
💡 Important Note: In large databases, using SELECT *
can be inefficient because it retrieves all data, even columns you don't need. It's generally recommended to specify only the columns you actually need for better performance.
Use specific column selection when:
Use SELECT *
when:
SELECT *
in most casesSELECT *
wisely - it's great for exploration but can be inefficient with large datasetsThroughout these lessons, you'll be working with a sample database containing data about Oscar-winning movies. This familiar and fun dataset will help you stay focused on learning SQL without being distracted by complex domain-specific data.
In this first exercise, you'll be working exclusively with the oscar_movies
table. As the lessons progress, you'll explore more tables and relationships between them.
Each lesson includes 5–6 hands-on tasks designed to reinforce the concept just covered. These tasks will give you both practical coding experience and a better understanding of how SQL works in real-world scenarios.
Take your time with each one—experiment, break things, and try variations. That's one of the best ways to learn!
Ready to practice SQL? Try our coding challenges →