UGC-NET Dec 2012 · SQL Queries

MCQ · 2 marks · Problem DBMS-SQL-0008

Given a Relation POSITION (Posting-No, Skill), then the query to retrieve all distinct pairs of posting-nos. requiring skill is
  1. A
    Select p.posting-No, p.posting-No from position p where p.skill=p.skill and p.posting-No < p.posting-No
  2. B
    Select p$_1$.posting-No, p$_2$.posting-No from position p$_1$, position p$_2$  where p$_1$.skill=p$_2$.skill
  3. C
    Select p$_1$.posting-No, p$_2$.posting-No from position p$_1$, position p$_2$  where p$_1$.skill=p$_2$.skill and p$_1$.posting.No < p$_2$.posting-No
  4. D
    Select p$_1$.posting-No, p$_2$.posting-No from position p$_1$, position p$_2$  where p$_1$.skill=p$_2$.skill and p$_1$.posting.No = p$_2$.posting-No

Solve it on GATE DA practice →More Relational Model & SQL problems

Show the worked solutionTo pair two different postings that need the same skill, join POSITION with itself using two aliases and require p1.skill = p2.skill. Adding p1.posting-No \(<\) p2.posting-No removes self-pairs and keeps each unordered pair only once.(A) Uses a single alias, so the condition compares a row with itself — incorrect.(B) Includes self-pairs and both orders of every pair — incorrect.(D) Equality returns only self-pairs — incorrect.Answer: C

GATE DA practice: past exam problems by chapter, with worked solutions · gatedaprep.com