20.07.2013 Views

Beginning SQL

Beginning SQL

Beginning SQL

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.

Chapter 10<br />

Perhaps you need to view attendance for all active members in Golden State.<br />

SELECT ActiveMemberAttendance.*<br />

FROM ActiveMemberAttendance<br />

WHERE (State = ‘Golden State’)<br />

ORDER BY LastName, FirstName<br />

The preceding results sets (illustrated in Figure 10-3) give you all of the fields from all three base tables,<br />

filtered by attendance and sorted by name and meeting attended. Because you are basing the results on<br />

one or more base queries, the <strong>SQL</strong> is easy to work with and easy to read. As you can see, you built a base<br />

query that joins all the required tables together. Once you did that, you could easily filter out only the<br />

active members or only the active members in Golden State.<br />

Figure 10-3<br />

Field Views<br />

Another type of view is the field view, which selects all of the records but only some of the fields. For<br />

example, suppose you need to build a list of all members, meeting dates, and meeting addresses.<br />

SELECT LastName, FirstName, MeetingDate, MemberAttended, [Meeting Street],<br />

[Meeting City], [Meeting State]<br />

FROM MemberAttendance<br />

ORDER BY LastName, FirstName<br />

This query provides exactly the fields you requested and does so for every row of the view, ordered by<br />

last name, as shown in Figure 10-4<br />

Figure 10-4<br />

Filtered Windowed Views<br />

292<br />

Windowed views display selected columns from selected rows. In other words, they limit the view of data<br />

in both the number of columns displayed as well as the number of rows displayed. The limitation on the<br />

number of columns is created by specifying only a subset of all the columns in the SELECT clause of the<br />

statement. The limitation on the number of rows is created by the WHERE clause, which specifies a subset<br />

of all the rows in the table. Thus, you create a rectangular window into the larger possible data set.

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

Saved successfully!

Ooh no, something went wrong!