retagged by
3,382 views
22 votes
22 votes

Suppose a database consist of the following relations:

SUPPLIER (SCODE,SNAME,CITY).
PART (PCODE,PNAME,PDESC,CITY).
PROJECTS (PRCODE,PRNAME,PRCITY).
SPPR (SCODE,PCODE,PRCODE,QTY).

 Write SQL programs corresponding to the following queries:

  1. Print PCODE values for parts supplied to any project in DEHLI by a supplier in DELHI.
  2. Print all triples <CITY, PCODE, CITY> such that a supplier in first city supplies the specified part to a project in the second city, but do not print the triples in which the two CITY values are same.
retagged by

6 Answers

0 votes
0 votes

I) More efficient query

Select A.pcode

from SPPR as A JOIN Projects as PR ON A.PRcode=PR.PRcode JOIN Supplier as SU ON SP.Scode=SU.Scode

where SP.city="Delhi" and PR.city="Delhi" ;

0 votes
0 votes

Using Natural join 

(i)    

select PCODE
from SUPPLIER S natural join SPPR SP join PROJECTS P using(PRCODE)
where P.PRCITY = "Delhi" and S.CITY = "Dehi"

(ii) 

select S.CITY, SP.PCODE, P.PRCITY
from SUPPLIER S natural join SPPR SP natural join PROJECTS P 
where P.PRCITY <> S.CITY 

 

edited by

Related questions

52 votes
52 votes
2 answers
2
Kathleen asked Sep 12, 2014
6,522 views
Find the number of binary strings $w$ of length $2n$ with an equal number of $1's$ and $0's$ and the property that every prefix of $w$ has at least as many $0's$ as $1's....
27 votes
27 votes
1 answer
4
Kathleen asked Sep 12, 2014
3,896 views
Analyse the circuit in Fig below and complete the following table$${\begin{array}{|c|c|c|}\hline\textbf{a}& \textbf{b}& \bf{ Q_n} \\\hline0&0\\\ 0&1 \\ 1&0 \\ 1...