Documente Academic
Documente Profesional
Documente Cultură
Use Branch and PropertyForRent tables in examples (a), (b) and (c).
Branch {branchNo, street, city, telNo, faxNo}
Pk
Staff {stafffNo, fNname, lName, position, sex, salary, branchNo}
pk
fk
PropertyForRent {propertyNo, street, city, type, rooms, rent, staffNo, branchNo}
Pk
fk
fk
Branch
branchNo
street
city
telNo
faxNO
B5
22 Dear Rd
London
0171-886-1212
0171-886-1214
B7
16 Argyll St
Aberdeen
01224-67125
01224-67111
B3
163 Main St
Glasgow
0141-339-2178
0141-339-4439
B4
38 Manse Rd
Bristol
0117-916-1170
0117-776-1114
B2
56 Clover Dr
London
0181-963-1030
0181-453-7992
PropertyForRent
propertyNo
street
city
type
rooms
rent
staffNo
branchNo
PA14
16 Holland
Aberdeen
House
650
SA9
B7
PL94
6 Argyll St
London
Flat
400
SL41
B5
PG4
6 Lawrence St
Glasgow
Flat
350
SG14
B3
PG36
2 Manor Rd
Glasgow
Flat
375
SG37
B3
PG21
18 Dale Rd
Glasgow
House
600
SG37
B3
PG16
5 Novar Dr
Glasgow
Flat
450
SG14
B3
ii)
(SELECT city
FROM Branch
WHERE city IS NOT NULL)
UNION
(SELECT city
FROM PropertyForRent
WHERE city IS NOT NULL);
Result
City
London
Glasgow
Aberdeen
Bristol
SELECT
*
FROM
Branch
WHERE city IS NOT NULL)
UNION CORRESPONDING BY city
(SELECT *
FROM
PropertyForRent
WHERE city IS NOT NULL);
b) INTERSECT Operator: Construct a list of all cities where there is both a branch office and a property
i)
ii)
(SELECT city
FROM Branch)
INTERSECT
(SELECT city
FROM PropertyForRent);
Result
city
London
Glasgow
Aberdeen
(SELECT *
FROM Branch)
INTERSECT CORRESPONDING BY city
(SELECT *
FROM PropertyForRent);
c) Except (MINUS in Oracle) Operator: construct a list of all cities where there is branch office but no properties.
i)
ii)
(SELECT city
FROM Branch)
EXCEPT
(SELECT city
FROM PropertyForRent);
(SELECT *
FROM branch)
EXCEPT CORRESPONDING BY city
(SELECT *
FROM PropertyForRent);
Result
city
Bristol
ii)
SELECT city
FROM Branch b
WHERE NOT EXISTS
( SELECT *
FROM PropertyForRent p
WHERE b.city = p.city);
bCity
Glasgow
Bristol
London
Property1
PropertyNo
PA14
PL94
PG4
pCity
Aberdeen
London
Glasgow
propertyNo
PG4
NULL
PL94
pCity
Glasgow
NULL
London
propertyNo
PA14
PG4
PL94
pCity
Aberdeen
Glasgow
London
Result
bCity
NULL
Glasgow
Bristol
London
propertyNo
PA14
PG4
NULL
PL94
pCity
Aberdeen
Glasgow
NULL
London