Database Tutorial #3: PostgreSQL — Advanced Queries

Basic SELECT queries only get you so far. Real applications need joins, aggregations, and complex filtering. This tutorial covers the SQL features you will use every day. We assume you have PostgreSQL running. See PostgreSQL Setup and Basics if you need to set that up first. Sample Schema Let’s use a simple e-commerce schema for all examples: CREATE TABLE users ( id uuid DEFAULT gen_random_uuid() PRIMARY KEY, name text NOT NULL, email text UNIQUE NOT NULL, created_at timestamptz DEFAULT NOW() ); CREATE TABLE orders ( id uuid DEFAULT gen_random_uuid() PRIMARY KEY, user_id uuid REFERENCES users(id), status text NOT NULL DEFAULT 'pending', total decimal(10, 2) NOT NULL, created_at timestamptz DEFAULT NOW() ); CREATE TABLE order_items ( id uuid DEFAULT gen_random_uuid() PRIMARY KEY, order_id uuid REFERENCES orders(id), product text NOT NULL, quantity integer NOT NULL, price decimal(10, 2) NOT NULL ); JOINs JOINs combine rows from multiple tables based on a related column. ...

August 3, 2026 · 7 min

Database Tutorial #2: PostgreSQL Setup and Basics

PostgreSQL is the most popular open-source database in the world. It is fast, reliable, and packed with features. This tutorial gets you up and running with PostgreSQL 17. We use Docker so you do not need to install PostgreSQL on your computer. Start PostgreSQL with Docker docker run -d \ --name postgres17 \ -e POSTGRES_PASSWORD=secret \ -e POSTGRES_USER=admin \ -e POSTGRES_DB=myapp \ -p 5432:5432 \ postgres:17 This starts PostgreSQL 17 in the background. Let’s break down the options: ...

August 3, 2026 · 6 min

Database Tutorial #1: SQL vs NoSQL — When to Use What

You are building a new app. You need to store data. Now comes the question: should I use SQL or NoSQL? This is one of the most common decisions in backend development. The wrong choice can hurt performance, scalability, and developer experience. The right choice makes everything simpler. This article explains both options clearly so you can make the right call. What Is SQL? SQL databases are relational databases. Data is stored in tables. Tables have rows and columns. Every row has the same structure, defined by the table schema. ...

August 3, 2026 · 6 min

DevTools Capstone: Building and Deploying a Full-Stack App with Git, Docker, and SQL

This is the final article in the DevTools series. In the previous 17 articles, you learned Git, Docker, and SQL separately. Now you will use all three together to build and deploy a real project. We will build a simple task management API with a PostgreSQL database. You will set up a Git repository with feature branches, write the API, Dockerize everything, add a CI/CD pipeline with GitHub Actions, and deploy it to a server. ...

June 16, 2026 · 15 min

SQL Tutorial #7: PostgreSQL Setup — A Real Database for Real Projects

You have been practicing with SQLite. It is great for learning. But for real projects, you need a real database. PostgreSQL (often called “Postgres”) is the most popular open-source relational database. It is used by companies of all sizes, from startups to enterprises. In this article, you will set it up, connect to it, and learn its unique features. In the previous article, you learned about indexes and performance. Now you will put everything together with a production-ready database. ...

June 16, 2026 · 12 min

SQL Tutorial #6: Indexes and Performance — Making Queries Fast

Your queries work. But they are slow. A simple SELECT takes seconds instead of milliseconds. On a table with millions of rows, it could take minutes. The fix is almost always the same: add an index. In the previous article, you learned about window functions. Now you will learn how to make all your queries run fast. What Is an Index? Think of a book’s index at the back. If you want to find “window functions” in a 500-page book, you have two options: ...

June 16, 2026 · 10 min

SQL Tutorial #5: Window Functions — Analytics Without GROUP BY

GROUP BY is great for summaries. But it collapses your rows. You get one row per group. What if you want the summary and the individual rows at the same time? That is what window functions do. They calculate across rows without removing any of them. In the previous article, you learned about aggregation and subqueries. Window functions are the next level. What Are Window Functions? A window function performs a calculation across a set of rows that are related to the current row. This set of rows is called a window. ...

June 15, 2026 · 11 min

SQL Tutorial #4: Aggregation and Subqueries — Summarizing Data

You know how to get individual rows. But what if you need answers like “How many books did we sell?” or “What is the average book price?” That is where aggregation comes in. In the previous article, you learned how to combine tables with JOINs. Now you will learn how to summarize data across many rows into a single answer. Aggregate Functions Aggregate functions take many rows and return a single value. ...

June 15, 2026 · 10 min

SQL Tutorial #3: JOINs — Combining Data from Multiple Tables

So far, you have worked with one table at a time. But real databases have many tables, and the interesting answers come from combining them. In the previous article, you learned how to add and modify data. Now you will learn how to pull data from multiple tables at once using JOINs. Why Tables Are Related In our bookstore database, we have separate tables for books and authors. Why not put everything in one table? ...

June 15, 2026 · 12 min

SQL Tutorial #2: INSERT, UPDATE, DELETE — Modifying Data

In the previous article, you learned how to read data with SELECT. But a database is not useful if you cannot add, change, or remove data. This article covers the three commands that modify data: INSERT, UPDATE, and DELETE. You will also learn about transactions — a way to make sure your changes are safe. Our Sample Database We continue with the same online bookstore database. If you need to set it up, copy the CREATE TABLE and INSERT statements from the first article. ...

June 14, 2026 · 10 min