next up previous
Next: DATA DEFINITION IN SQL Up: RELATIONAL MODEL OF DATA Previous: Relational Algebra

Querying database using Relational Algebra

(1) Get cnames of customers who live in "New York" and 
    order product "p01".

T1 = customers join orders
T2 = select[city="New York" and pid="p01"](T1)
RESULT = project[cname](T2)

(2) Get cids of customers who do not order part "p01".

T1 = project[cid](select[pid="p01"](orders))
T2 = project[cid](customers)
RESULT = T2 - T1

(3) Get cids of customers who order "p01" and "p02".

T1 = project[cid](select[pid="p01"](orders))
T2 = project[cid](select[pid="p02"](orders))
RESULT = T1 intersection T2

(4) Get pids of products for which orders have been placed
    by agents in "Dallas" or "Duluth"

T1 = agents join orders
T2 = project[pid](select[city="Dallas"](T1))
T3 = project[pid](select[city="Duluth"](T1))
RESULT = T2 union T3

(5) Get cids of customers who place orders through ALL
    agents located in "New York".

T1 = project[cid,aid](orders)
T2 = project[aid](select[city="New York"](agents))
RESULT = T1 div T2



Raj Sunderraman
Tue Apr 1 16:15:10 PST 1997