Wednesday, June 3, 2026
Cohort 3 | Project CloudIgnite Topics: SQL Advanced Queries, Amazon RDS Duration: ~3 hours
Key Takeaways
- ORDER BY: sort ascending (default) or descending; multiple columns (left = highest priority)
- GROUP BY + HAVING: group rows, then filter groups;
WHEREfilters rows,HAVINGfilters groups - Set operations: UNION (dedupe), UNION ALL (keep dupes), INTERSECT (common), MINUS (A not in B)
- JOINs: INNER (matching only), LEFT (all left + matching right), RIGHT (all right + matching left), FULL (all from both)
- Window functions:
OVER(PARTITION BY ... ORDER BY ...)— aggregate without collapsing rows;RANK()assigns rank per partition - Amazon RDS: fully managed relational DB; supports MySQL, PostgreSQL, Aurora, Oracle, SQL Server
- RDS Lab 160: DB Security Group (port 3306 from web SG only), DB Subnet Group (private subnets), Multi-AZ for high availability
- Architecture: Internet → EC2 (public subnet) → RDS (private subnet) — standard 3-tier security pattern
Table of Contents
- SQL Recap – ORDER BY, GROUP BY, HAVING
- Set Operations – UNION, INTERSECT, MINUS
- JOIN Operations
- Window Functions – OVER & RANK
- Amazon RDS – Lab 160
- CLF-C02 Exam Relevance
1. SQL Recap
ORDER BY (Sorting)
- Sorts query results by one or more columns.
- Default order is ascending (ASC); use
DESCfor descending. - Multiple columns: Priority goes left to right. The second column is only applied when the first column has equal values.
- You can reference columns by name or by column number (e.g.,
ORDER BY 2, 3).
-- Sort by surface area descending
SELECT name, continent, surfacearea
FROM country
ORDER BY surfacearea DESC;
-- Sort by multiple columns
SELECT name, continent, surfacearea
FROM country
ORDER BY continent, surfacearea DESC;
-- Sort by column number (equivalent to above)
SELECT name, continent, surfacearea
FROM country
ORDER BY 2, 3 DESC;
GROUP BY (Grouping)
- Groups rows that share the same value in a specified column.
- Typically used with aggregate functions like
COUNT(),SUM(),AVG().
-- Count number of countries per continent
SELECT continent, COUNT(name) AS countries
FROM country
WHERE continent = 'South America' AND population > 12000000
OR continent = 'Antarctica'
GROUP BY continent
ORDER BY 1, 2;
HAVING (Filtering Groups)
- Works like
WHEREbut is applied afterGROUP BY. - Use
WHEREto filter individual rows before grouping. - Use
HAVINGto filter aggregated/grouped results after grouping.
| Clause | Applied | Use Case |
|---|---|---|
WHERE | Before GROUP BY | Filter individual rows |
HAVING | After GROUP BY | Filter grouped/aggregated results |
-- Show only continents with more than 5 countries
SELECT continent, COUNT(name) AS countries
FROM country
GROUP BY continent
HAVING COUNT(name) > 5;
Key Rule: You cannot use aggregate functions (e.g.,
COUNT) in aWHEREclause — useHAVINGinstead.
2. Set Operations
Combines results from two or more SELECT queries. Both queries must return the same number of columns with compatible data types.
| Operation | Description |
|---|---|
UNION | Combines results, removes duplicates |
UNION ALL | Combines results, keeps duplicates |
INTERSECT | Returns only common rows in both results |
MINUS (or EXCEPT) | Returns rows in the first result that are NOT in the second |
Example with sets A = {1,2,3,4} and B = {3,4,5,6}:
| Operation | Result |
|---|---|
| A UNION B | {1, 2, 3, 4, 5, 6} |
| A UNION ALL B | {1, 2, 3, 4, 3, 4, 5, 6} |
| A INTERSECT B | {3, 4} |
| A MINUS B | {1, 2} |
| B MINUS A | {5, 6} |
-- Combine country names and city names (no duplicates)
SELECT name FROM country
UNION
SELECT name FROM city;
UNION vs JOIN:
UNIONcombines query results (rows from multiple queries).JOINcombines tables (columns from multiple tables).
3. JOIN Operations
Used to retrieve data from multiple related tables using a common column (usually a foreign key).
Types of JOIN
| Type | Description |
|---|---|
INNER JOIN | Returns only rows where there is a match in both tables (like intersection) |
LEFT JOIN | Returns all rows from the left table + matching rows from the right |
RIGHT JOIN | Returns all rows from the right table + matching rows from the left |
FULL JOIN | Returns all rows from both tables (like UNION) |
Interview Tip: JOIN types are very common questions in Data Analyst/Data Science interviews.
Syntax Example
-- Join city and country tables using country code
SELECT ci.id AS city_id,
ci.name AS city_name,
co.name AS country_name
FROM city ci -- 'ci' is a table alias
JOIN country co -- 'co' is a table alias
ON ci.countrycode = co.code;
- Table aliases (
ci,co) act as shorthand names to avoid repetition, especially in self-joins. - The
ONclause defines the join condition (which columns to match). - The joining column does not have to be a foreign key — any matching column works.
Visual Summary
INNER JOIN LEFT JOIN RIGHT JOIN FULL JOIN
A ∩ B A + (A ∩ B) B + (A ∩ B) A ∪ B
4. Window Functions
OVER()
- Allows aggregate functions to operate across a set of rows related to the current row, without collapsing them into one result (unlike
GROUP BY). - Often used with
PARTITION BYto divide data into groups, andORDER BYto sort within each partition. - Produces a running/cumulative total per row.
-- Cumulative population sum per region
SELECT name,
region,
population,
SUM(population) OVER (
PARTITION BY region
ORDER BY population
) AS running_total
FROM world.country
WHERE region IN ('Australia and New Zealand', 'South America');
RANK()
- Assigns a rank number to each row within a partition, based on the
ORDER BYcolumn. - Restarts ranking for each new partition.
-- Rank countries in each region by population (largest to smallest)
SELECT name,
region,
population,
RANK() OVER (
PARTITION BY region
ORDER BY population DESC
) AS ranked
FROM world.country
ORDER BY region, ranked;
OVER vs GROUP BY:
GROUP BYcollapses rows into one result per group.OVERkeeps all individual rows and adds a computed column alongside them.
5. Amazon RDS
Note: This section is directly relevant to the AWS CLF-C02 exam. See section below.
What is Amazon RDS?
- Relational Database Service (RDS) – a fully managed database service by AWS.
- Supports engines: MySQL, PostgreSQL, MariaDB, Oracle, SQL Server, Amazon Aurora.
- AWS handles: server provisioning, software installation, patching, updates, and backups.
RDS vs Self-Managed DB on EC2
| Feature | Amazon RDS | EC2 + DB |
|---|---|---|
| Management | Fully managed by AWS | You manage everything |
| Setup | Launch and use | Install & configure manually |
| Patching | Automatic | Manual |
| Backups | Automatic (configurable) | Manual |
Key Concepts from Lab 160
Security Group for RDS
- Created a dedicated DB Security Group.
- Inbound rule: MySQL/Aurora, port 3306, source = Web Security Group.
- This means only traffic from the web tier (EC2) can reach the database — the database is not directly accessible from the internet.
DB Subnet Group
- Defines which subnets RDS instances can be deployed in.
- Configured to use two private subnets across two Availability Zones.
- Ensures the database is not publicly accessible.
Multi-AZ Deployment
- Deploys the primary DB in one Availability Zone and a standby replica in another.
- If the primary fails, it automatically fails over to the standby — high availability.
- Multi-AZ DB Cluster = 2 standby instances (higher redundancy, higher cost).
Launching an RDS Instance (Lab Steps Summary)
- Create a DB Security Group (inbound: MySQL/Aurora from web SG).
- Create a DB Subnet Group using two private subnets.
- Launch RDS DB instance:
- Engine: MySQL
- Template: Dev/Test
- Deployment: Multi-AZ (2 instances)
- Instance class:
db.t3.medium - Storage: 20 GB, gp3
- VPC: Lab VPC (not default)
- Public access: No
- Security group: DB Security Group
- Disable performance insights & enhanced monitoring (for lab)
- Disable automated backups (for lab/testing)
- Connect via endpoint through a web application hosted on EC2.
Architecture Pattern
Internet → EC2 (Public Subnet) → RDS (Private Subnet)
The database sits in a private subnet and is only reachable through the EC2 instance, not directly from the internet. This is a standard 3-tier architecture security best practice.
Automation Note
- All RDS configurations can be scripted using Terraform or Python (Boto3 SDK) for repeatable deployments.
CLF-C02 Exam Relevance
The following topics from today's lecture map directly to the AWS Certified Cloud Practitioner (CLF-C02) exam objectives:
Domain 3: Cloud Technology & Services
| Topic Covered | CLF-C02 Relevance |
|---|---|
| Amazon RDS | Core AWS database service – know it's fully managed, supports multiple engines, and handles patching/backups |
| Multi-AZ Deployment | Related to High Availability and Fault Tolerance — key cloud concepts |
| Private Subnet for DB | Relates to security best practices and VPC architecture |
| Security Groups | Acts as a virtual firewall — understand inbound/outbound rules |
| DB Subnet Group | Understand how RDS uses subnets for deployment |
| Amazon Aurora | Listed as an RDS engine option — know it's AWS's proprietary, high-performance DB |
Domain 2: Security & Compliance
| Topic | Relevance |
|---|---|
| Placing RDS in private subnet | Principle of least privilege / defence in depth |
| Security Groups as firewall | Core network security concept |
| IAM mentioned for DB auth | Identity and access management for AWS resources |
Domain 1: Cloud Concepts
| Topic | Relevance |
|---|---|
| Fully managed services (RDS) | Understand the shared responsibility model — AWS manages the DB engine, you manage data and access |
| Multi-AZ = High Availability | Core cloud benefit: fault tolerance and reliability |
Study Tip: For CLF-C02, you don't need to know how to configure RDS step-by-step, but you should be able to:
- Describe what RDS is and why it's used.
- Differentiate RDS from running a database on EC2.
- Understand Multi-AZ and its purpose (high availability, not performance).
- Know that RDS supports MySQL, PostgreSQL, MariaDB, Oracle, SQL Server, and Aurora.
Upcoming Sessions
| Date | Content |
|---|---|
| Tomorrow | RDS demonstration + DynamoDB + DynamoDB demonstration |
| Friday | Challenge lab (if not completed tomorrow) |
| Saturday 2–6 PM | JOIN operation demonstration + Labs 273 & 274 revisit |