Q.Write the output of SQL queries
You're viewing a preview — the full solution, concept, methods & PYQ mapping are locked.
Start your 14-day free trial to unlock the full solution →These SQL queries retrieve filtered records, aggregate counts by city, list unique cities, and find extreme vaccination dates from the VACCINATION_DATA table.
Understanding the Table Structure
The VACCINATION_DATA table tracks vaccination records for five individuals. Each row contains a unique identifier (VID), personal details (Name, Age), two dose dates (Dose1, Dose2), and the City of residence. Notice that Gazala and Shiksha have NULL values in Dose2, meaning they haven't received their second dose yet—this detail matters when filtering or aggregating data.
Query (a): Filtering by Age and Completion Status
SELECT Name, Age FROM VACCINATION_DATA WHERE Dose2 IS NOT NULL AND Age > 40;
This query asks for names and ages of people who meet two conditions: they must have completed both doses (Dose2 IS NOT NULL) and be older than 40. Walking through the table:
- Jenny (27) fails the age test
- Harjot (55) passes both—has Dose2 and is over 40
- Srikanth (43) passes both—has Dose2 and is over 40
- Gazala (75) passes the age test but has NULL in Dose2
- Shiksha (32) fails both conditions
Output:
| Name | Age |
|---|---|
| Harjot | 55 |
| Srikanth | 43 |
Query (b): Counting Records by City
SELECT City, COUNT(*) FROM VACCINATION_DATA GROUP BY City;
GROUP BY collapses rows sharing the same City value into groups, and COUNT(*) tallies how many records fall into each group. Delhi appears twice (Jenny, Srikanth), Mumbai twice (Harjot, Shiksha), and Kolkata once (Gazala).
Output:
| City | COUNT(*) |
|---|---|
| Delhi | 2 |
| Mumbai | 2 |
| Kolkata | 1 |
The order of cities in the output depends on the database implementation—SQL doesn't guarantee any particular sequence unless you add ORDER BY.
Query (c): Listing Unique Cities
SELECT DISTINCT City FROM VACCINATION_DATA;
DISTINCT eliminates duplicate values, so even though Delhi and Mumbai each appear twice in the table, they're listed only once in the result.
Output:
| City |
|---|
| Delhi |
| Mumbai |
| Kolkata |
Unlock everything free for 14 days
- Full step-by-step solutions
- Concept-first explanations
- Methods, shortcuts & mistakes
- PYQ mapping + timed mock tests
Full access for 14 days. No credit card required.