Why Every Data Professional Needs SQL
If you work with data, SQL is not optional anymore—it’s fundamental.
Machine learning models, dashboards, and experiments are exciting, but none of them happen without solid data preparation underneath. Most of that preparation—extracting, cleaning, joining, and aggregating data—is driven by SQL in tools like Hive, Teradata, and many relational databases.
For many people, SQL is the first “programming language” they get to use. It certainly was for me. Before SQL, I spent my days buried in Excel: VLOOKUPs, pivot tables, and manual reports created over and over. Once I learned SQL, I could replace all of that with a single script that generated the same analysis automatically. That’s when I realized how powerful it is.
Yes, you can replicate a lot of SQL logic with tools like Pandas, but in the real world, production data often lives in databases and data warehouses. To work effectively with those systems, you need to be comfortable with SQL.
This guide walks you through three things:
- Installing a local SQL environment
- Getting a practice database set up
- Learning core SQL concepts by running real queries
1. Setting Up a Local SQL Environment
The best way to learn SQL is to actually run it yourself. Online sandboxes are fine for a quick taste, but they don’t let you use your own data or build real workflows.
For a beginner-friendly setup, MySQL is a great choice:
- It’s open source.
- It runs on macOS, Linux, and Windows.
- MySQL Workbench provides a visual interface to write and run queries.
Step 1: Install MySQL
- Download MySQL Community Server for your operating system.
- Run the installer and follow the prompts.
- During installation you’ll be asked to set a root password—make sure you remember it, because you’ll need it to connect later.
Step 2: Allow Local File Access (Optional but Useful)
Create a configuration file named my.cnf with something like:
[client] port=3306 [mysqld] port=3306 secure_file_priv='' local-infile=1
Point your MySQL server to this file through the configuration panel, then restart the server. This setup allows you to load data from local files when needed.
Step 3: Install MySQL Workbench
Download and install MySQL Workbench, then open it. You should see a “Local Instance” connection already created. Click it, enter the password you set during installation, and you’ll be connected to your local MySQL server.
On the left, under Schemas, you’ll see existing databases. Out of the box, there’s usually only a system schema, which isn’t very useful for learning. Let’s fix that.
2. Loading a Practice Database (Sakila)
To learn SQL properly, you need a realistic dataset with multiple tables and relationships. MySQL’s Sakila sample database is perfect for this—it models a fictional DVD rental store with movies, actors, rentals, and more.
Install the Sakila Database
- Download the Sakila ZIP from the official MySQL documentation site.
- Unzip the archive.
- In MySQL Workbench, go to File → Run SQL Script and select sakila-schema.sql to create the tables.
- Repeat the step with sakila-data.sql to insert sample data.
Once the scripts finish running, refresh the Schemas panel. You should now see a sakila schema with multiple tables such as film, inventory, actor, and others.
Now you’re ready to write SQL.
3. Writing Your First Queries
The Basic Structure of a SQL Query
Most SELECT queries follow this general pattern:
SELECT col1, SUM(col2) AS col2_sum, AVG(col3) AS col3_avg FROM some_table WHERE some_condition GROUP BY col1 ORDER BY col2_sum DESC;
Key parts:
- SELECT – which columns or expressions you want to return
- FROM – which table (or tables) you’re reading from
- WHERE – filters rows before aggregation
- GROUP BY – groups rows so you can aggregate them
- ORDER BY – sorts the final result
This pattern is enough to handle a lot of everyday data questions.
Example: Simple Filters
Try a few queries against the sakila.film table:
-- All movies released in 2006 SELECT * FROM sakila.film WHERE release_year = 2006; -- PG-rated movies longer than 50 minutes SELECT * FROM sakila.film WHERE length > 50 AND rating = 'PG';
Playing with this kind of query helps you get comfortable with filters and the overall flow.
4. Joining Tables
Real databases rarely store everything in a single table. Relationships between tables are expressed through joins.
Two of the most common join types are:
- LEFT JOIN – keep all rows from the left table, and bring in matching rows from the right table (missing matches show up as NULL).
- INNER JOIN – only return rows where both tables have matching keys.
General syntax for a LEFT JOIN:
SELECT A.col1, A.col2, B.col3, B.col4 FROM A LEFT JOIN B ON A.col2 = B.col3;
Example: Copies of Each Film in Inventory
Suppose you want to know how many copies of each movie are in your store’s inventory. The inventory table contains a row per physical copy of a film.
A first step could be:
SELECT film_id, COUNT(*) AS num_copies FROM sakila.inventory GROUP BY film_id ORDER BY num_copies DESC;
This tells you how many copies exist per film_id, but raw IDs aren’t very readable. The film table contains the movie titles, so you can join the two:
SELECT i.*, f.title FROM sakila.inventory AS i LEFT JOIN sakila.film AS f ON i.film_id = f.film_id;
Now each inventory record includes the human-readable film title. From here, you might want the number of copies per title, which brings us to subqueries.
5. Subqueries (Inner Queries)
One approach is to store the joined result in a temporary table and then aggregate it. But that creates extra tables you need to manage. Instead, SQL lets you nest one query inside another—this is a subquery.
For example:
SELECT title, COUNT(*) AS num_copies FROM ( SELECT i.film_id, f.title FROM sakila.inventory AS i LEFT JOIN sakila.film AS f ON i.film_id = f.film_id ) AS temp GROUP BY title ORDER BY num_copies DESC;
The inner query (temp) produces a virtual table with film_id and title. The outer query then groups by title and counts how many copies there are. No physical temp table required.
Subqueries allow you to build complex logic step by step while keeping everything in a single statement.
6. Filtering Aggregated Results With HAVING
Sometimes you want to filter based on an aggregated value, such as “only show films with two or fewer copies.”
You can’t use WHERE directly on an aggregated column like COUNT(*), because the aggregation happens after the filtering. Instead, you use the HAVING clause:
SELECT title, COUNT(*) AS num_copies FROM ( SELECT i.film_id, f.title FROM sakila.inventory AS i LEFT JOIN sakila.film AS f ON i.film_id = f.film_id ) AS temp GROUP BY title HAVING COUNT(*) <= 2 ORDER BY num_copies ASC;
- WHERE filters rows going into the aggregation.
- HAVING filters rows after they’ve been grouped and aggregated.
Both are useful; they just operate at different stages of the query.
7. Practice: Ask Questions, Answer With SQL
If you’ve followed along to this point, you already know more SQL than a lot of casual users. The next step is practice.
Use the Sakila database (or your own data) and try to answer questions such as:
- Which actor appears in the largest number of distinct films?
- Which film category or genre is rented most frequently?
- How many customers rented at least one movie in a given month?
The more questions you ask and answer, the more naturally SQL will come to you.
8. Where to Learn More
This article is just a starting point. To go deeper—into topics like UNION, string operations, date functions, and more complex joins—consider structured courses or books dedicated to SQL for data analysis and data science.
However you choose to continue, the key is the same: keep writing real queries against real data. That’s how you truly “learn SQL the hard way”—by using it.