SQL Query Execution Steps (Ordered Execution)
SQL Query:
SELECT Rating, MIN(Age) AS youngest_age
FROM Sailors
WHERE Age >= 18
GROUP BY Rating
HAVING COUNT(*) >= 2;
Step 1: FROM Clause (Selecting Table)
Loads the 'Sailors' table.
| Sid | Sname | Rating | Age |
|------|--------|--------|------|
| 22 | John | 7 | 45 |
| 23 | Mike | 1 | 33 |
| 24 | Alex | 8 | 55.5 |
| 25 | Sam | 8 | 25.5 |
| 26 | Tom | 10 | 35 |
| 27 | Jerry | 7 | 35 |
| 28 | Chris | 9 | 40 |
| 29 | Steve | 3 | 25.5 |
| 30 | Rick | 3 | 63.5 |
Step 2: WHERE Clause (Filter Eligible Sailors)
Filters sailors who are at least 18 years old.
| Sid | Sname | Rating | Age |
|------|--------|--------|------|
| 22 | John | 7 | 45 |
| 23 | Mike | 1 | 33 |
| 24 | Alex | 8 | 55.5 |
| 25 | Sam | 8 | 25.5 |
| 26 | Tom | 10 | 35 |
| 27 | Jerry | 7 | 35 |
| 28 | Chris | 9 | 40 |
| 29 | Steve | 3 | 25.5 |
| 30 | Rick | 3 | 63.5 |
Step 3: GROUP BY Clause (Grouping by Rating)
Groups sailors based on their rating.
| Rating | Sailors (Age) |
|--------|--------------------|
| 7 | (45, 35) |
| 1 | (33) |
| 8 | (55.5, 25.5) |
| 10 | (35) |
| 9 | (40) |
| 3 | (25.5, 63.5) |
Step 4: HAVING Clause (Filter Ratings with at Least 2 Sailors)
Removes ratings with fewer than 2 sailors.
| Rating | Sailors (Age) |
|--------|--------------------|
| 7 | (45, 35) |
| 8 | (55.5, 25.5) |
| 3 | (25.5, 63.5) |
Step 5: SELECT Clause (Find Minimum Age in Each Group)
Finds the youngest sailor in each rating group.
| Rating | Youngest Age |
|--------|-------------|
| 7 | 35 |
| 8 | 25.5 |
| 3 | 25.5 |
Summary of Execution Order:
1. FROM → Load the 'Sailors' table.
2. WHERE → Filter sailors aged 18 or older.
3. GROUP BY → Group sailors by 'Rating'.
4. HAVING → Keep only ratings with at least 2 sailors.
5. SELECT → Retrieve the minimum age for each rating.