SQL (Structured Query Language) is the language of data. If data lives in a database—and most organizational data does—SQL is how you access it. The good news? You don't need to learn all of SQL. A focused subset of commands covers 90% of what analysts do daily.
Why SQL Matters for Analysts
- Most company data is stored in relational databases
- SQL is required in 60%+ of data analyst job postings
- It's far more efficient than Excel for large datasets
- It works with virtually every database system
- It's a skill that transfers across industries and tools
The Essential Commands
SELECT — Choosing Your Columns
The most basic and most important command:
SELECT first_name, last_name, email
FROM customers;
Use SELECT * to get all columns, but in practice, always specify what you need—it's faster and clearer.
WHERE — Filtering Rows
SELECT product_name, price
FROM products
WHERE price > 1000
AND category = 'Electronics';
Common operators: =, !=, >, <, >=, <=, LIKE, IN, BETWEEN, IS NULL
ORDER BY — Sorting Results
SELECT product_name, sales_amount
FROM sales
ORDER BY sales_amount DESC;
DESC for descending (highest first), ASC for ascending (default).
GROUP BY — Aggregating Data
This is where SQL gets powerful for analysis:
SELECT department,
COUNT(*) as employee_count,
AVG(salary) as avg_salary
FROM employees
GROUP BY department;
Common aggregate functions: COUNT(), SUM(), AVG(), MIN(), MAX()
HAVING — Filtering Grouped Data
WHERE filters rows before grouping; HAVING filters after:
SELECT department, AVG(salary) as avg_salary
FROM employees
GROUP BY department
HAVING AVG(salary) > 80000;
JOIN — Combining Tables
Real-world analysis almost always requires data from multiple tables:
SELECT orders.order_id,
customers.name,
orders.total_amount
FROM orders
INNER JOIN customers ON orders.customer_id = customers.id;
Types of joins you should know:
- INNER JOIN — Only matching rows from both tables
- LEFT JOIN — All rows from the left table, matching from right
- RIGHT JOIN — All rows from the right table, matching from left
Subqueries — Queries Within Queries
For more complex analysis:
SELECT name, salary
FROM employees
WHERE salary > (SELECT AVG(salary) FROM employees);
Real-World Analysis Patterns
Here are patterns you'll use all the time:
Top N analysis:
SELECT customer_name, SUM(order_total) as total_spent
FROM orders
GROUP BY customer_name
ORDER BY total_spent DESC
LIMIT 10;
Year-over-year comparison:
SELECT YEAR(order_date) as year,
SUM(revenue) as total_revenue
FROM sales
GROUP BY YEAR(order_date)
ORDER BY year;
Finding duplicates:
SELECT email, COUNT(*) as count
FROM customers
GROUP BY email
HAVING COUNT(*) > 1;
Practice Resources
The best way to learn SQL is by writing queries:
- SQLZoo — Interactive browser-based tutorials
- LeetCode — SQL practice problems (easy to hard)
- Mode Analytics — Free SQL tutorial with a real database
- Your own data — The most motivating way to learn
Tips for Success
- Write readable queries — Use proper indentation and aliases
- Start with SELECT * to explore — Then narrow down your columns
- Test incrementally — Build complex queries step by step
- Comment your code — Future you will appreciate it
- Learn to read error messages — They usually tell you exactly what's wrong
SQL is a core module in our Data Analysis Training program. You'll practice with real datasets and build queries you can use in your job.