Overview

Course Overview β€” SQL Set Operations & Advanced Filtering Practice | DataSosi
Course Designer
Professor Mark Lokanan
Royal Roads University
Academic Director  Β·  Canadian Institute of Artificial Intelligence (CiAI)
Architect of Next-Generation AI and Machine Learning Systems for Fraud Detection and Financial Crime Analytics
Course Overview Β· SQL Practice Series Β· Part 6

SQL Set Operations &
Advanced Filtering Practice

Combining query outputs, validating relationships, applying strict and flexible conditions, and moving data between tables.

Advanced SQL goes beyond single-table queries and simple JOINs. Analysts need to combine result sets, validate relationships with subqueries, compare values against multiple benchmarks, and move data between tables. Across six parts, you will master UNION, UNION ALL, EXISTS, ANY, ALL, and INSERT INTO SELECT β€” the advanced operations that power enterprise SQL workflows. Same tables as Parts 1–5. Every query includes an AI prompt and a validated SQL answer.
6 Parts
48 Practice Queries
Same Tables as Parts 1–5
AI-Assisted Learning
Certificate of Completion

Course Learning Objectives

  • Use UNION to combine multiple SELECT query results into a single deduplicated output, following the column count and type compatibility rules.
  • Use UNION ALL to combine complete query outputs while preserving all records including duplicates, for operational data stacking and frequency analysis.
  • Use EXISTS to filter records based on whether related data exists in a connected table, using correlated subqueries.
  • Use ANY to compare a value against multiple subquery results where the condition must hold for at least one β€” the flexible threshold operator.
  • Use ALL to compare a value against every subquery result where the condition must hold for all β€” the strict threshold operator.
  • Use INSERT INTO SELECT to copy records from one table into another using a SELECT query, with filtered copying via WHERE.
Six parts β€” click any part to see its topics and practice focus.
Set Union

Part 1 covers UNION β€” combining results from multiple SELECT queries into a single deduplicated output. Students learn the three UNION rules (same column count, compatible types, consistent order), understand that the output column name comes from the first SELECT, and apply UNION to merge business datasets.

Topic 1
Combining Query Results

Merging records from different tables or queries into a single output list.

Topic 2
Removing Duplicates

UNION automatically deduplicates β€” each unique value appears once regardless of how many queries produce it.

Topic 3
Multi-Query Reporting

Building unified reference lists by combining IDs, names, and values from multiple business tables.

Topic 4
Unified Business Outputs

Merging financial values, names, and categories from different tables into a consolidated report.

  • Practice focus: combining names, IDs, categories, and financial values across users, products, orders, transactions, subscriptions, support tickets, and campaigns
  • 8 practice queries β€” each with an AI prompt and a validated SQL answer
Full Stacking

Part 2 covers UNION ALL β€” the faster variant that keeps every record including repeated values. Students learn when to choose UNION ALL over UNION, how it enables operational data stacking, and why it is preferred for frequency analysis and complete audit trails.

Topic 1
Combining All Records

UNION ALL keeps every row from every SELECT β€” no deduplication is performed.

Topic 2
Preserving Duplicates

When repeated values are valid data that must not be removed from the combined output.

Topic 3
Operational Data Stacking

Merging complete datasets from two tables into one for full operational coverage.

Topic 4
Full Result Analysis

Why UNION ALL is faster than UNION and when that performance advantage matters most.

  • Practice focus: stacking names, IDs, categories, statuses, and financial values across all major business tables with all records preserved
  • 8 practice queries β€” each with an AI prompt and a validated SQL answer
Existence Checks

Part 3 covers EXISTS β€” the relational filter that checks whether a subquery returns any rows. Students learn the correlated subquery pattern, understand that EXISTS returns only outer table columns, and apply EXISTS to validate relationships across all major table pairs.

Topic 1
Existence Checks

EXISTS evaluates TRUE when the subquery finds at least one match; FALSE when it finds none.

Topic 2
Linked Record Validation

Confirming business relationships β€” users with transactions, products with orders, campaigns with events.

Topic 3
Relational Filtering

The correlated WHERE clause that links the subquery to each row of the outer table.

Topic 4
Operational Activity Checks

EXISTS across all table relationships β€” users, products, campaigns, orders, and sessions.

  • Practice focus: validating relationships across users-transactions, users-orders, products-order_items, users-subscriptions, users-tickets, campaigns-events, users-sessions, and orders-order_items
  • 8 practice queries β€” each with an AI prompt and a validated SQL answer
Flexible Threshold

Part 4 covers ANY β€” the flexible subquery comparison operator. Students learn that > ANY beats the minimum, < ANY is below the maximum, and = ANY is equivalent to IN. They apply ANY for cross-table value comparisons across products, transactions, subscriptions, and order items.

Topic 1
Comparing Against Grouped Values

ANY returns TRUE if the condition holds for at least one subquery value β€” the minimum threshold.

Topic 2
Flexible Conditional Analysis

> ANY = above the minimum. < ANY = below the maximum. = ANY = equivalent to IN.

Topic 3
Multi-Value Comparisons

Cross-table comparisons β€” transaction amounts vs subscription fees, product prices vs transaction amounts.

Topic 4
Operational Threshold Checks

Identifying records that exceed the minimum benchmark in a comparison group.

  • Practice focus: ANY comparisons across products, transactions, subscriptions, and order_items using > ANY and < ANY operators
  • 8 practice queries β€” each with an AI prompt and a validated SQL answer
Strict Threshold

Part 5 covers ALL β€” the strictest subquery comparison operator. Students learn that > ALL equals > MAX, < ALL equals < MIN, and that zero rows is a valid result when no value satisfies the strict condition. They apply ALL for extreme performance comparisons across business datasets.

Topic 1
Comparing Against All Values

ALL returns TRUE only if the condition holds for every single subquery value β€” the strictest test.

Topic 2
Strict Conditional Filtering

> ALL = above the maximum. < ALL = below the minimum. != ALL = not in the list.

Topic 3
Business Performance Comparisons

Identifying top records that exceed the entire comparison group β€” the highest performers.

Topic 4
Interpreting Empty Results

Zero rows from ALL is analytically meaningful β€” no value satisfies the strict cross-group condition.

  • Practice focus: ALL comparisons across products, transactions, subscriptions, and order_items; understanding when zero rows is the correct and expected result
  • 8 practice queries β€” each with an AI prompt and a validated SQL answer including notes on expected empty results
Data Movement

Part 6 covers INSERT INTO SELECT β€” the SQL command for copying records between tables. Students learn the two-step pattern (CREATE TABLE then INSERT), how WHERE filters which rows are copied, and that source data is never changed. Each exercise uses DROP TABLE IF EXISTS for clean repeat runs.

Topic 1
Copying Records

INSERT INTO SELECT copies rows from a source table into a pre-existing destination table.

Topic 2
Data Movement

Moving business data between tables as part of archive, reporting, and ETL workflows.

Topic 3
Table-to-Table Insertion

The two-step pattern: CREATE TABLE first, then INSERT INTO destination SELECT from source.

Topic 4
Business Data Replication

Filtered copying with WHERE β€” completed orders, active subscriptions, open tickets, Email campaigns.

  • Practice focus: copying users, completed orders, active subscriptions, refund transactions, open tickets, Email campaigns, Desktop sessions, and Software products into archive tables
  • 8 two-step practice exercises β€” CREATE TABLE then INSERT INTO SELECT, each with an AI prompt and validated SQL

Course at a Glance

Six parts Β· 48 practice queries Β· same tables as Parts 1–5

PartCommand / OperatorCore FocusPractice
Part 1UNIONCombine queries and deduplicate β€” names, IDs, categories, financial values8 Queries
Part 2UNION ALLStack all records including duplicates β€” faster than UNION, preserves frequency8 Queries
Part 3EXISTSRelational existence checks β€” filter by whether related activity exists in a linked table8 Queries
Part 4ANYFlexible threshold β€” TRUE if condition holds for at least one subquery value8 Queries
Part 5ALLStrict threshold β€” TRUE only if condition holds for every subquery value; zero rows is valid8 Queries
Part 6INSERT INTO SELECTCopy and archive records β€” CREATE TABLE then INSERT with WHERE filters8 Queries
AI-Assisted SQL Learning

Every practice question in this course includes a business question, an AI prompt for ChatGPT or Copilot, the validated SQL answer, and guidance on interpreting the result. Students learn to prompt effectively, validate advanced SQL logic, troubleshoot subquery conditions, and connect set operations and data movement to real analytical workflows.

What You Leave With

Six advanced SQL operations. Forty-eight practice queries. An enterprise SQL toolkit.

UNION

Clean deduplicated merging of multiple query results for unified business reporting.

UNION ALL

Fast, complete data stacking that preserves every record including repeated values.

EXISTS

Relational existence filtering β€” validating whether linked business activity is present.

ANY

Flexible threshold comparison β€” TRUE if the condition holds for at least one value.

ALL

Strict threshold comparison β€” TRUE only if the condition holds for every value.

INSERT INTO SELECT

Automated record copying, archiving, and data movement between business tables.

AI-Assisted Workflow

Prompting, validating, and troubleshooting advanced SQL in a professional analytical context.

Certificate

Certificate of Completion from the Canadian Institute of Artificial Intelligence (CiAI), powered by DataSoSi.