20.07.2013 Views

Beginning SQL

Beginning SQL

Beginning SQL

SHOW MORE
SHOW LESS

Create successful ePaper yourself

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

1<br />

2<br />

3<br />

4<br />

5<br />

6<br />

7<br />

8<br />

9<br />

10<br />

11<br />

12<br />

13<br />

14<br />

15<br />

But how can that be? When you ran the query earlier it returned 29 rows, and many of the FilmId and<br />

MemberId values were the same, and yet there’s no duplication of MemberId and FilmId in this results set.<br />

These results are different from the previous results because, by default, the UNION operator merges the<br />

two queries but includes only rows that are unique. If you want all rows returned in the results set, regardless<br />

of whether they are unique, you need to use the ALL statement, as illustrated in the following <strong>SQL</strong>:<br />

SELECT FilmId FROM Films<br />

UNION ALL<br />

SELECT MemberId FROM MemberDetails;<br />

When you execute this query, you get all the rows even if some are identical:<br />

1<br />

2<br />

3<br />

4<br />

5<br />

6<br />

7<br />

8<br />

Selecting Data from Different Tables<br />

Table continued on following page<br />

229

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

Saved successfully!

Ooh no, something went wrong!