Q.(a) Consider the following tables Student and Sport : Table : Student ADMNO NAME CLASS 1100 MEENA X 1101 VANI XI Table : Sport ADMNO GAME 1100 CRICKET 1103 FOOTBALL What will be the output of the following statement ? SELECT * FROM Student, Sport;
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 →The first query produces a Cartesian product (every row of Student paired with every row of Sport), while the second set of queries tests your understanding of aggregate functions, GROUP BY, HAVING, date comparisons, and pattern matching in SQL.
(a) The Cartesian Product
The statement SELECT * FROM Student, Sport; is a cross join — it combines every row from the first table with every row from the second table. This is called a Cartesian product.
Student has two rows (ADMNO 1100 and 1101). Sport also has two rows (ADMNO 1100 and 1103). So the output will have 2 × 2 = 4 rows. Each row of Student is paired with each row of Sport, regardless of whether the ADMNO values match.
The result will look like this:
| ADMNO | NAME | CLASS | ADMNO | GAME |
|---|---|---|---|---|
| 1100 | MEENA | X | 1100 | CRICKET |
| 1100 | MEENA | X | 1103 | FOOTBALL |
| 1101 | VANI | XI | 1100 | CRICKET |
| 1101 | VANI | XI | 1103 | FOOTBALL |
Notice that the ADMNO column appears twice — once from each table. This is rarely useful in practice; you would normally add a WHERE clause to match related rows.
A Cartesian product multiplies every row of one table with every row of another. If Student had 100 rows and Sport had 50, the output would be 5000 rows — often unintended and computationally expensive.
(b) Queries on the GARMENT table
Let us examine each query one by one.
(i) SELECT DISTINCT(COUNT(FCODE)) FROM GARMENT;
This query first counts the number of non-null FCODE values in the entire table. There are 6 rows, and every row has an FCODE, so COUNT(FCODE) returns 6. That single number (6) is then passed to DISTINCT. Since there is only one value, the output is simply:
COUNT(FCODE)
6
DISTINCT here is redundant — it applies to the single aggregated value. The parentheses around COUNT(FCODE) are also unnecessary; DISTINCT COUNT(FCODE) would work the same way.
(ii) SELECT FCODE, COUNT(*), MIN(PRICE) FROM GARMENT GROUP BY FCODE HAVING COUNT(*)>1;
This groups rows by FCODE. Let us see how many rows each FCODE has:
- F01: G103 (FROCK), G104 (TULIP SKIRT), G106 (FORMAL PANT) → 3 rows
- F02: G102 (SLACKS), G105 (BABY TOP) → 2 rows
- F03: G101 (EVENING GOWN) → 1 row
The HAVING COUNT(*)>1 keeps only groups with more than one row — so F03 is dropped. For the remaining groups, the query selects the FCODE, the count of rows, and the minimum price in that group.
For F01: minimum price among 1000, 1550, 1250 is 1000.
For F02: minimum price among 750, 1500 is 750.
Output:
| FCODE | COUNT(*) | MIN(PRICE) |
|---|---|---|
| F01 | 3 | 1000 |
| F02 | 2 | 750 |
(iii) SELECT TYPE FROM GARMENT WHERE ODR_DATE >'2021-02-01' AND PRICE <1500;
This filters rows where the order date is after 1 February 2021 AND the price is less than 1500. Let us check each row:
- G101: date 2008-12-19 — before 2021, so fails.
- G102: date 2020-10-20 — before 2021, fails. …
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.