SQL Lesson 1: SELECT statement

March 27, 2025 | Categories: Information

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. Queries follow a specific syntax, which we will explore in the following exercises.

Understanding Tables and Data Representation

As mentioned in the introduction, you can think of a SQL table as representing a type of entity—for example, a table named Dogs could store information about different breeds of dogs. Each row in the table represents a specific instance of that entity (e.g., a pug, a beagle, a golden retriever), while columns define the attributes shared by all instances (e.g., fur color, tail length, breed).

Writing a Basic SQL Query

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.

Selecting Specific Columns:

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.

Selecting All Columns:

If we want to retrieve all columns from a table without listing each one individually, we 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. However, in large databases, using SELECT *  can be inefficient, so it’s generally recommended to specify only the columns you actually need.


✅ Key Takeaways


📝 Exercise Overview

Throughout 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.

Leave a comment:

Comments: