Skip to main content

Resource Guide: SQL

Last Updated: January 2024

SQL, which is an acronym for Structured Query Language, is a language widely used to interact with most relational databases. You can create, query, update, and delete databases using SQL. While having a simple syntax, SQL is very powerful and allows you to efficiently query large databases.

“Database” is not a synonym of “dataset.” Databases are collections of data typically controlled by database management systems (such as MySQL or SQLite). Databases are common for large quantities of data, often consisting of multiple tables of data, that multiple users need to access efficiently and securely at the same time. Databases are particularly useful when you need to add, update, delete, or use individual observations or subsets of data frequently.

It’s important to note that, while SQL is one language, there are multiple dialects. There are standards for SQL, but different vendors of database management systems provide various versions of SQL syntax, such as MySQL, PostgreSQL, and SQLite. However, most of the syntax, particularly basic syntax, is very similar across dialects.

Getting Started

Query Existing Databases

Select Star SQL
If you’re completely new to SQL, this is a great place to start, particularly if you only need to query an existing database. This is a fun tutorial, which introduces SQL through real-life stories and questions. The explanations are very good.

Query, but also Create, Update, and Delete

These resources cover similar ground in different ways. Choose the one that best fits your needs and preferences!

Programiz: Introduction to SQL and Databases
Approachable introduction to SQL and databases. This tutorial explains the difference between relational and non-relational databases and common statements to create, query, update, and delete databases.

Khan Academy: Intro to SQL
Guided introduction to SQL. If you prefer videos, you’ll like this one. In addition to explanations, it provides exercises to practice and consolidate your learning.

Northwestern Databases Workshops
This series of four workshops was designed and taught by Research Computing and Data Services. The series includes materials on how to select and join, explore, and update and change data, as well as how to create and design databases.

Getting Some Practice

W3Schools: SQL Exercises
Practice makes perfect! W3Schools—a great resources for learning about coding—provides easy, fill-in-the-blank type exercises for you to make sure that you’re learning.

Reference

Sadly, you’re not going to remember everything that you learned. These tutorials will help you go back to specific elements that you may need a refresher on.

W3Schools: SQL Tutorial
This tutorial comprehensively provides explanations and examples of different aspects of SQL.

GeeksforGeeks: SQL Tutorial
This tutorial provides descriptions and examples for common operations using SQL. Similarly to W3Schools, GeeksforGeeks is also a great place to learn about coding.

Getting Better

More Practice

w3resource: SQL Exercises
Want more practice? This website provides exercises and a web-based editor to write and execute code for common tasks.

DataLemur: SQL Problems
The exercises provided above are meant to check your knowledge of specific aspects of SQL—not your ability to solve problems. In contrast, this website provides questions that you need to answer using SQL. Although the questions are meant to practice for data science interviews, you can use them to consolidate your knowledge.

Knight Lab: SQL Murder Mystery
Are you loving SQL and want more practice? This is a fun tutorial developed by Northwestern’s Knight Lab where you need to use SQL to investigate and solve a crime!

SQL Meets R

Posit: Best Practices in Working with Databases
If you plan to connect to a database with R, this guide will help you get setup.  If you’re a user of the dplyr package, you may have already picked up on the similarities to SQL.  The dbplyr package allows you to write dplyr code to interact with databases instead of SQL code — the package translates the dplyr code to SQL for you behind the scenes!  A good option if you’re an R user.

Deep Dive into SQL and Databases

Database Systems: The Complete Book
Hector Garcia-Molina, Jeffrey D. Ullman, and Jennifer Widom
This is a detailed and comprehensive book about databases. The book covers the material taught in the database sequence at Stanford, which includes SQL (mostly chapter 6).   This is a theoretical, not practical, book.  If you want to learn more about database theory, this is a good place to start.

SQL for Smarties: Advanced SQL Programming
As the title indicates, this book is an advanced and comprehensive guide to SQL programming, covering topics not included in other tutorials.  It is a practical book that uses only standard SQL.  Note, however, that more advanced functions and features are more likely to deviate from the standard SQL syntax across database systems.