Learn SQL
Written by:
Dave Fowler
Reviewed by:
Matt David
Welcome to our PostgreSQL interactive SQL Tutorial! We’ve designed this specifically for tech-savvy folks to learn enough SQL to be able to do their own analysis and data fetching.
We’ve added a big innovation to our tutorial that makes it quite different: Because we believe the best way to learn SQL is by playing around, we’ve created an interactive SQLBox for you to follow along and play with writing queries from the very start.The SQLBox takes your input and runs it against a live PostgreSQL database that we’re hosting.
-
Quick Introductory SQL Concepts
Learn how to use SQL with your PostgreSQL database. In this interactive SQL data tutorial, get an introduction that is designed to get you querying your PostgreSQL database as quickly as possible. Learn SQL basics, tables and SQLbox.
-
SELECT
Learn the SELECT SQL statement with your PostgreSQL database in this interactive SQL data tutorial. The SELECT statement is a basic SQL command to access data.
-
FROM
This interactive SQL tutorial will explain the FROM command with syntax and use cases on how to interact with your data in the PostgreSQL database. Learn how to use the SQL FROM command by following the steps in this interactive tutorial.
-
ORDER BY
Learn how to use the SQL ORDER BY command in PostgreSQL. The ORDER BY command is used to sort your result data in ascending or descending order. Follow the interactive SQL tutorial to use cases and best practices for the ORDER BY command.
-
LIMIT and OFFSET
Learn how to LIMIT the number of results that are returned you can simply use the LIMIT SQL command at the end of the query to specify. You can use the LIMIT command on your PostgreSQL database. Read the tutorial to learn more.
-
Browsing the SCHEMA
SCHEMA is the collection of tables and relationships in your database. In this interactive SQL tutorial, learn how to browse a SCHEMA with PostgreSQL.
-
Basic SQL Practice Grounds
After you've got the basic SQL fundamentals. Put that knowledge to the test in these interactive SQL practice exercises.
Basic SQL
-
WHERE
Learn how to use the WHERE command in PostgreSQL. In this interactive SQL tutorial, learn the best practices of the WHERE command for analysis and exploration.
-
Operators
Learn about Operators in SQL and how to use them in Postgres. Operators are used to specify conditions in a SQL statement.
-
Aggregate Functions
Learn about the COUNT function in SQL. The COUNT command is used to returns the count of how many rows there are. This interactive SQL tutorial will teach you how to COUNT.
-
GROUP BY
The GROUP BY SQL statement is used to aggregate functions like COUNT, MAX, MIN, SUM and AVG. In this interactive SQL tutorial, learn to use the GROUP BY .
-
JOIN Relationships and JOINing Tables
A JOIN SQL statement combines two data from two tables together. In this interactive SQL tutorial, learn the most common JOIN statements.
-
DATE and TIME Functions
DATE and TIME values in PostgreSQL have a whole special set of functions and operators for their proper use. Learn how to use dates in PostgreSQL in this interactive SQL tutorial, so you can get the DATE and TIME of your data analysis.
-
Mid Level SQL Practice Grounds
After you've mastered mid-level SQL fundamentals, put that knowledge to the test in these interactive SQL practice exercises.
Mid-Level SQL
-
What is the difference between UNION and UNION ALL
UNION ALL keeps all of the records from each of the original data sets, UNION removes any duplicate records.
-
Exclude a Column
Learn how to exclude a column in the SELECT statement of your query
-
Additional Practice
Practice common SQL commands with simple questions.
-
How to Create a Copy of a Database in PostgreSQL
Learn how to create a copy of a database in postgres using psql.
-
How to Export PostgreSQL Data to a CSV or Excel File
Learn how to export PostgreSQL data to a CSV or Excel file. Follow these instructions to copy tables, copy a query results, and open CSV files.
-
How to Replace Nulls with 0s in SQL
This article talks about how to use the UPDATE statement to clean data.
-
How to Start a PostgreSQL Server on Mac OS X
This article shows how to start a PostgreSQL server using both Homebrew and the potgres app on a Mac.
-
Importing Data from CSV in PostgreSQL
This article outlines how to use psql to import data from csv files.
-
Insert multiple rows
Insert multiple rows into a table in a single SQL query using Postgres
-
List the tables in SQLite opened with ATTACH (In progress)
Learn how to list the tables in a SQLite database file that was opened with ATTACH?
-
Meta commands in PSQL
This article talks about what meta commands are and provides a list of some common examples.
-
Outputting Query Results to Files with \o
This article discusses how to use the o meta command to output to a text file
-
How To Generate Random Data in PostgreSQL
You can generate random values and sequences in SQL. Learn how with this interactive PostgreSQL tutorial.
-
Show Tables in Postgres (In progress)
Learn how to show Tables in Postgres using the command line
-
SQL Cheat Sheet
Reference common commands and operators that are often forgotten
-
UPDATE with JOIN in SQL (In progress)
How can I do an UPDATE statement with JOIN in SQL?
-
Using ALTER in PostgreSQL
Learn the different potential uses of the ALTER command in PSQL. Add and drop columns from tables. Rename and change schemas and more.
-
5 Redshift SQL shortcuts
Learn how to use row number, date trunc, mod, split part, and rename to improve your queries.
-
AND OR Boolean Logic
This post goes into detail on how Boolean logic works and how Boolean logic can be molded with truth tables
-
Conditional Logic
Learn how to use CASE WHEN, IIF, and UNION with WHERE to apply conditional logic within a Postgres SQL query
-
Copying Data Between Tables
Learn to copy data from a table or query into another table using the INSERT command in psql.
-
Drop all tables Postgres (In progress)
Learn how to drop all tables in your schema in Postgres using the command line.
-
Export to CSV with \copy
This article discusses how to export data from psql to a csv file using the copy commands
-
Find Duplicates
Learn how to find duplicate values in your database using SQL.
-
PostgreSQL Generate_Series
This article outlines how to use PostgreSQL's Generate_Series() function
-
Hierarchical data in SQL (In progress)
Learn what are the options for storing hierarchical data in a relational database.