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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Nested <strong>Queries</strong> (Example)<br />

“Name and <strong>in</strong>come of Frank’s father”<br />

<strong>select</strong><br />

from<br />

where<br />

f.name, f.<strong>in</strong>come<br />

person f, fatherChild fc<br />

f.name = fc.father and fc.child = 'Frank'<br />

<strong>select</strong><br />

from<br />

where<br />

f.name, f.<strong>in</strong>come<br />

person f<br />

f.name = (<strong>select</strong> fc.father<br />

from fatherChild fc<br />

where fc.child = 'Frank')<br />

71<br />

Nested <strong>Queries</strong>: Opera<strong>to</strong>rs<br />

In the where clause, the result of a nested query can be related <strong>to</strong><br />

other values by way of several opera<strong>to</strong>rs:<br />

• equality and other comparisons (the result of the nested query must<br />

be unique)<br />

• if it is not certa<strong>in</strong> that the result of the nested query is unique, the<br />

nested query can be preceded by one of the keywords:<br />

— any: true, if the comparison is true for at least one of the result<br />

tuples of the nested query<br />

— all: true, if the comparison is true for all the result tuples of the<br />

nested query<br />

• the opera<strong>to</strong>r <strong>in</strong>, which is equivalent <strong>to</strong> =any<br />

• the opera<strong>to</strong>r not <strong>in</strong>, which is equivalent <strong>to</strong> all<br />

• the opera<strong>to</strong>r exists<br />

72

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

Saved successfully!

Ooh no, something went wrong!