SQL (Structured Query Language)
This covers the core principles of SQL, the standard language for communicating with databases.
1. Logical Order of Execution
The order in which you write SQL (SELECT -> FROM…) differs from the order in which the database actually executes it. Not knowing this can cause errors.
- FROM / JOIN: First, find the tables to retrieve data from.
- WHERE: Filter out rows that don’t meet the conditions beforehand. (Performance key)
- GROUP BY: Group the remaining data.
- HAVING: Keep only groups that satisfy the conditions.
- SELECT: Select and calculate the columns to output. (Window Functions happen here too!)
- ORDER BY: Sort the results.
- LIMIT: Limit the number of results.
Why?: This is why you can’t use an alias created in
SELECTin theWHEREclause.WHEREis executed beforeSELECT!
2. Set Theory
JOIN is based on the concept of sets.
- INNER JOIN: Intersection () - Data that exists in both tables.
- LEFT JOIN: All of + () - Keep all from the left, attach from the right if exists.
- FULL OUTER JOIN: Union () - Keep everything from both sides.
- CROSS JOIN: Cartesian product () - All possible combinations (multiply row counts).
Curriculum
1. JOIN (Table Combination)
Learn how to combine multiple tables to extract meaningful data.
INNER JOIN,LEFT JOIN,FULL OUTER JOIN,CROSS JOIN- Get Started with JOIN →
2. NULL Handling
Learn how to safely handle NULL values, the biggest enemy in data analysis.
IFNULL(),COALESCE(),SAFE_DIVIDE()- Get Started with NULL Handling →
3. String Functions
Learn how to cut, concatenate, and transform text data.
SUBSTR(),CONCAT(),REGEXP_EXTRACT()- Get Started with String Functions →
4. Date/Time Functions
Learn the basics of time series analysis: DATE and TIMESTAMP handling.
DATE_TRUNC(),DATE_DIFF(),FORMAT_DATE()- Get Started with Date/Time Functions →
5. Aggregation and Grouping
Learn GROUP BY techniques to summarize data and gain insights.
COUNT(),SUM(),AVG(),COUNTIF()- Get Started with Aggregation and Grouping →
6. Window Functions (Advanced)
Learn window functions, the flower of SQL, for calculating relationships between rows.
RANK(),LEAD(),LAG(),SUM() OVER()- Get Started with Window Functions →
7. CTE (Common Table Expression)
A readability technique for writing complex queries like building with Lego blocks.
- Using the
WITHsyntax - Get Started with CTE →