Skip to content
Worked Examples · Example 9.24

Q.a) Display all possible combinations of tuples of relations DANCE and MUSIC.

b) From the all possible combinations of tuples of relations DANCE and MUSIC display only those rows such that the attribute name in both have the same value.
Rajasthan RbseTextbookSubjective· 4mImportance★★★★★
41% · 39/95 Questions
🔒 Locked · start free trial →

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 →

(a) "All possible combinations of tuples" is the Cartesian product — SELECT * FROM DANCE, MUSIC;. With DANCE (4 rows) and MUSIC (5 rows), it pairs every DANCE row with every MUSIC row: 4 × 5 = 20 rows (Table 9.23).

(b) Keeping only the pairs whose Name values agree turns that product into an equi-join — SELECT * FROM DANCE D, MUSIC M WHERE D.Name = M.Name;, giving the 2 rows of Table 9.24.

Concept understanding — product then selection

The join is not a primitive operation. It is built from two simpler ones:

OperationSymbolEffectRows produced
Cartesian productDANCE × MUSICpair every tuple of DANCE with every tuple of MUSICm × n
Selection on the productσ<sub>condition</sub>keep only the pairs that satisfy the condition≤ m × n
Equi-joinDANCE ⋈<sub>Name = Name</sub> MUSICthe two above, combinedusually far fewer

So an equi-join is σ<sub>DANCE.Name = MUSIC.Name</sub>(DANCE × MUSIC). Part (a) builds the raw material; part (b) filters it.

The relations from the textbook (Section 9.10.1)

Table 9.18: DANCE

SNoNameClass
1Aastha7A
2Mahira6A
3Mohit7B
4Sanjay7A

Table 9.19: MUSIC

SNoNameClass
1Mehak8A
2Mahira6A
3Lavanya7A
4Sanjay7A
5Abhay8A

DANCE has degree 3, cardinality 4. MUSIC has degree 3, cardinality 5.


(a) All possible combinations — the Cartesian product

mysql> SELECT * FROM DANCE, MUSIC;

DANCE X MUSIC has degree 3 + 3 = 6 and cardinality 4 × 5 = 20 — exactly Table 9.23, which the textbook itself points to as the answer to part (a):

Table 9.23: DANCE X MUSIC

SNoNameClassSNoNameClass
1Aastha7A1Mehak8A
2Mahira6A1Mehak8A
3Mohit7B1Mehak8A
4Sanjay7A1Mehak8A
1Aastha7A2Mahira6A
2Mahira6A2Mahira6A
3Mohit7B2Mahira6A
4Sanjay7A2Mahira6A
1Aastha7A3Lavanya7A
2Mahira6A3Lavanya7A
3Mohit7B3Lavanya7A
4Sanjay7A3Lavanya7A
1Aastha7A4Sanjay7A
2Mahira6A4Sanjay7A
3Mohit7B4Sanjay7A
4Sanjay7A4Sanjay7A
1Aastha7A5Abhay8A
2Mahira6A5Abhay8A
3Mohit7B5Abhay8A
4Sanjay7A5Abhay8A

20 rows in set.

Degree of DANCE × MUSIC = degree(DANCE) + degree(MUSIC) = 3 + 3 = 6

Cardinality = cardinality(DANCE) × cardinality(MUSIC) = 4 × 5 = 20

Watch out

Most of these 20 rows are meaningless — "Aastha danced and Mehak sang" is not a fact about anybody. Only two of the 20 pairs (row 6 and row 16 above) have matching names — those are exactly the two rows part (b) isolates. A Cartesian product on real tables can explode fast: 1,000 rows × 1,000 rows gives a million rows. Omitting the join condition by mistake is exactly how a query accidentally becomes a Cartesian product.


(b) Keeping only the rows where Name matches — the equi-join

mysql> SELECT * FROM DANCE D, MUSIC M WHERE D.Name = M.Name;
``` …

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.