next up previous contents
Next: Who is older Up: Simple Queries Previous: Which employee earns

Which dept is on which floor?

 

This query illustrates a query concerning the relationship between two variables.

ENG: which dept is on which floor
SYN: (s(np(det(which))(n(n(dept))))(vp(v(is))
      (pp(prep(on))(np(det(which))(n(n(floor)))))))
 PT: `dept:fv1 and `floor:fv2 and `on:fv2:`be:fv1
FOL: dept(fv1)&floor(fv2)&on(fv1,`be,fv2)
URC: {fv1,fv2;[fv1,*]:loc&[*,fv2]:loc&[fv1,fv2]:loc}
DRC: {fv1:loc![dept],fv2:loc![floor];
      [fv1,*]:loc&[*,fv2]:loc&[fv1,fv2]:loc}
OP1: {fv1:loc![dept],fv2:loc![floor];[fv1,fv2]:loc}
TRC: {fv1!dept,fv2!floor;fv1:loc,fv2:loc;
      exists(tuple1:loc,tuple1!dept=fv1!dept&tuple1!floor=fv2!floor)}
OP2: {fv1!dept,fv2!floor;fv1:loc,fv2:loc;
      exists(tuple1:loc,tuple1!dept=fv1!dept&tuple1!floor=fv2!floor)}
OP3: {fv1!dept,fv2!floor;fv1:loc,fv2:loc;fv1!floor=fv2!floor}
SQL: SELECT DISTINCT fv1.dept, fv2.floor FROM loc fv1, loc fv2 
      WHERE fv1.floor=fv2.floor;

|dept      |floor |
|-----------------|
|admin     |     6|
|food      |     1|
|shoe      |     1|
|toy       |     2|
|-----------------|
(4 rows)



Chris Fox, September 1995