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/Advanced queries

UNION, INTERSECT, EXCEPT

156 min

Sometimes you need to combine the results of several queries into one list, or compare them with each other. That is what set operations do.

The condition: matching columns

The combined queries must have the same number of columns with compatible types. The column names of the result come from the first query.

UNION and UNION ALL

Everyone at the university — students and teachers — in one list:

university· Try changing it
SELECT first_name, last_name, 'talaba' AS role FROM students
UNION ALL
SELECT first_name, last_name, 'ustoz' FROM teachers
ORDER BY last_name
LIMIT 10;
  • UNION ALL adds everything, duplicates included (faster);
  • UNION removes duplicates.
university· Try changing it
SELECT city FROM students
UNION
SELECT 'Toshkent';

INTERSECT — in both

Last names that appear among students and among teachers:

university· Try changing it
SELECT last_name FROM students
INTERSECT
SELECT last_name FROM teachers;

EXCEPT — in the first, not in the second

Last names found among students but not among teachers:

university· Try changing it
SELECT last_name FROM students
EXCEPT
SELECT last_name FROM teachers;
1Exercise

Show, in one list without repeats, every city that appears among customers (customers.city) and in orders (orders.city).


2Exercise

Show the customer_id of the customers who placed orders but never wrote a review (use EXCEPT).


Remember

  • UNION ALL adds, UNION adds without duplicates.
  • INTERSECT is the overlap, EXCEPT is the difference.
  • The queries must have the same number and types of columns.
Previous lessonSubqueriesNext lessonWITH: named queries

Contents

  • The condition: matching columns
  • UNION and UNION ALL
  • INTERSECT — in both
  • EXCEPT — in the first, not in the second
  • Remember
LearnPracticeProblemsArenaLeaderboard

SQLab