15  SQL : The Sequel

Earlier, we introduced SQL (Structured Query Language) — the language data analysts use to communicate with databases.
Now, it’s time to see SQL in action and understand how it helps retrieve and analyze data efficiently.

Think of this as “SQL: The Sequel” — bigger, faster, and more powerful than spreadsheets!


15.0.1 Why SQL?

SQL can do much of what spreadsheets can — store, organize, and analyze data —
but it’s built for scale.

  • For small datasets (e.g., a few hundred rows), spreadsheets work fine.
  • For large datasets (thousands or millions of rows), SQL is the better choice.

Spreadsheets are like a compact car; SQL is a high-speed train — both get you there, but one handles heavier loads far better.


15.0.2 How SQL Works with Databases

Just like languages require mutual understanding, SQL needs a database system that “speaks” SQL.

Some common SQL-based databases include:
- MySQL
- PostgreSQL
- SQLite
- Microsoft SQL Server
- Google BigQuery

Even though these databases differ, SQL commands are largely universal
once you learn SQL, you can use it across many systems.


15.0.3 What Is a Query?

A query is a request for specific information from a database.
It’s like asking your database a question — and SQL helps you ask it clearly and precisely.

Here’s a basic structure of an SQL query:

SELECT column_name(s) FROM table_name WHERE condition;


15.0.4 SQL Query Breakdown

  • SELECT — tells the database what information you want to view.
  • FROM — identifies the table that holds the data.
  • WHERE — filters results based on conditions.

15.0.5 Example 1: Select All Data

To retrieve all data from a table named movies:

SELECT * FROM movies;

This command selects every column and every row in the table.


15.0.6 Example 2: Filter Specific Data

To see only movies in the Action genre:

SELECT * FROM movies WHERE genre = 'Action';

This query filters the results to show just the rows where genre equals “Action.”


15.0.7 Example 3: Select Specific Columns

To view only the movie title and release year:

SELECT title, release_year FROM movies WHERE genre = 'Action';

This query retrieves only the relevant columns instead of the entire dataset.


15.0.8 Why This Matters

Understanding the SELECT–FROM–WHERE structure gives you the foundation for all future SQL work.
Once you’re comfortable with these, you’ll be able to:

  • Sort and group data
  • Join multiple tables
  • Calculate summaries and averages
  • Build advanced analytical queries

Key takeaway:
SQL empowers data analysts to explore massive datasets efficiently.
With just a few lines of code, you can uncover patterns, trends, and insights that would take hours to find in a spreadsheet.