SQLab
LearnPracticeProblemsArenaLeaderboard
© 2026 SQLab · Tashkent
SQLab

Learn SQL right in the browser — nothing to install.

Platform

  • Learn
  • Practice
  • Problems
  • Arena
  • Leaderboard

Who it is for

  • Students
  • Teachers
  • Universities
© 2026 SQLab. All rights reserved.Made in Uzbekistan, for students.
LearnPracticeProblemsArenaLeaderboard
0/26

Basics

  • What is a database?
  • Your first SELECT
  • WHERE: picking the rows you need
  • IN, BETWEEN, LIKE and NULL
  • Sorting, LIMIT and DISTINCT

Calculations

  • Expressions, functions and CASE
  • Working with dates
  • COUNT, SUM, AVG, MIN, MAX
  • GROUP BY and HAVING

Joining tables

  • Keys and relations
  • INNER JOIN
  • LEFT JOIN and rows without a match
  • Several tables and the self join

Advanced queries

  • Subqueries
  • UNION, INTERSECT, EXCEPT
  • WITH: named queries
  • Window functions

Creating and changing tables

  • CREATE TABLE: types and constraints
  • INSERT, UPDATE, DELETE
  • ALTER, DROP, TRUNCATE
  • Designing a database well

Going professional

  • Indexes and EXPLAIN
  • Transactions and ACID
  • Views: saved queries
  • Functions, procedures and triggers
  • Users, privileges and backups
Learn/Joining tables

LEFT JOIN and rows without a match

128 min

INNER JOIN silently drops the rows that have no match. Yet often those are exactly the interesting ones: “customers who never ordered”, “groups without a curator”, “students without a single grade”.

LEFT JOIN

Every row of the left table stays. Where there is no match in the right table, its columns come out as NULL.

university· Try changing it
SELECT g.name, t.last_name AS curator
FROM study_groups g
LEFT JOIN teachers t ON t.id = g.curator_id
ORDER BY t.last_name NULLS FIRST, g.name;

Groups without a curator show NULL as curator.

Finding the rows without a match

The most useful trick: LEFT JOIN + WHERE right.id IS NULL.

shop· Try changing it
SELECT c.first_name, c.last_name
FROM customers c
LEFT JOIN orders o ON o.customer_id = c.id
WHERE o.id IS NULL;

These are the customers who have never placed an order.

RIGHT JOIN and FULL JOIN

  • RIGHT JOIN mirrors LEFT JOIN: the right table stays complete. It is usually clearer to swap the tables and write LEFT JOIN.
  • FULL JOIN keeps the unmatched rows from both sides.

PostgreSQL supports FULL OUTER JOIN.

Careful: is the condition in WHERE or in ON?

In a LEFT JOIN, a condition on the right table written in WHERE rejects the unmatched rows (the NULLs), and the LEFT JOIN quietly becomes a plain JOIN. A condition on the right table belongs in ON:

shop· Try changing it
SELECT c.first_name, COUNT(o.id) AS cancelled
FROM customers c
LEFT JOIN orders o ON o.customer_id = c.id AND o.status = 'cancelled'
GROUP BY c.id, c.first_name
ORDER BY cancelled DESC
LIMIT 5;

COUNT(o.id) does not count NULLs, so a customer without cancelled orders gets 0.

1Exercise

Show the names of the products that have no reviews at all (reviews).


2Exercise

Show each faculty’s name and the number of its teachers. A faculty without teachers should show 0.


Remember

  • LEFT JOIN keeps the whole left table; unmatched rows get NULL on the right.
  • Rows without a match: LEFT JOIN … WHERE right.id IS NULL.
  • Conditions on the right table go in ON, or the LEFT JOIN stops working.
Previous lessonINNER JOINNext lessonSeveral tables and the self join

Contents

  • LEFT JOIN
  • Finding the rows without a match
  • RIGHT JOIN and FULL JOIN
  • Careful: is the condition in WHERE or in ON?
  • Remember
LearnPracticeProblemsArenaLeaderboard

SQLab