A brief introductory course to relational databases and SQL, targeting people interested in learning SQL for data analysis. This course does not cover database administration topics such as indexing, transactions, or stored procedures.
Platform: Google BigQuery
Datasets: nyu-datasets.imdb and nyu-datasets.facebook
- Entities, Primary Keys, and Attributes
- Relations and Cardinality (One-to-One, One-to-Many, Many-to-Many)
- From ER Diagram to Relational Schema
- SQL Statements for Creating Tables
- Navigating a Database
- Selection queries:
SELECT,AS,DISTINCT,ORDER BY,LIMIT - Filtering with
WHERE: Boolean operators,IN,LIKE,BETWEEN - Handling
NULLvalues - Conditional logic with
CASE WHEN - Attribute-level functions: string, date, and NULL functions
- Inner Joins
- Self Joins
- Outer Joins (LEFT, RIGHT, FULL)
- Semi-joins and Anti-joins
- Aggregation functions:
COUNT,SUM,AVG,MAX,MIN,STDEV GROUP BYon single and multiple attributes- Filtering groups with
HAVING - Combining JOINs and GROUP BY
- Subqueries with single-value results
- Semi-joins and Anti-joins using
IN - Derived tables
WITHclause (Common Table Expressions)- Comparison: CTEs vs. temporary tables vs. views
- Window definition:
OVER(ORDER BY) - Ranking functions:
RANK,DENSE_RANK,ROW_NUMBER - Partitioned windows:
OVER(PARTITION BY ... ORDER BY ...) - Offset functions:
LEAD,LAG,FIRST_VALUE,LAST_VALUE - Frame definitions and rolling aggregations
- StrataScratch — SQL interview questions from tech companies
- LeetCode Database Problems
- DataLemur — SQL interview prep
- W3Resource SQL Exercises
- Mode SQL Tutorial — Basics to advanced
- Khan Academy: Introduction to SQL — Video-based intro
- W3Schools SQL — Hands-on examples
- Codecademy: Learn SQL
- How to Teach People SQL — Great visualizations
- Learning MySQL — Comprehensive textbook
- Become a SELECT Star! by Julia Evans — Visual SQL zine
- SQL Data Manipulation for Data Scientists — Advanced techniques
- SQL Best Practices — Writing readable SQL
All notebooks use Google BigQuery. To run them:
- Open any notebook in Google Colab (use the badge above)
- Authenticate with your Google account
- Replace
'your-project-id'with your Google Cloud project ID
The queries use publicly accessible datasets in the nyu-datasets project.