29.01.2014 Views

Introduction to Database Systems Queries in SQL The select ...

Introduction to Database Systems Queries in SQL The select ...

Introduction to Database Systems Queries in SQL The select ...

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>SQL</strong> and Relational Algebra (cntd)<br />

It may be necessary <strong>to</strong> rename attributes<br />

• <strong>in</strong> the target list (as <strong>in</strong> relational algebra)<br />

• <strong>in</strong> the Cartesian product (<strong>in</strong> particular, when the query refers<br />

twice <strong>to</strong> the same table)<br />

<strong>select</strong> X.A1 as B1, ...<br />

from R1 X, R2 Y, R1 Z<br />

where X.A2 = Y.A3 and ...<br />

which can also be written as<br />

<strong>select</strong> X.A1 as B1, ...<br />

from R1 as X, R2 as Y, R1 as Z<br />

where X.A2 = Y.A3 and ...<br />

23<br />

<strong>SQL</strong> and Relational Algebra (cntd)<br />

<strong>select</strong> X.A1 as B1, Y.A4 as B2<br />

from R1 X, R2 Y, R1 Z<br />

where X.A2 = Y.A3 and Y.A4 = Z.A1<br />

X ← R1, Y ← R2, Z ← R1,<br />

ρ B1←X.A1, B2←Y.A4 (<br />

π X.A1,Y.A4 (σ X.A2 = Y.A3 and Y.A4 = Z.A1 (X x Y x Z)))<br />

24

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!