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.

The good news is that everything you learned in Chapter 2 about the WHERE clause can be applied to<br />

WHERE clauses used with SELECT statements. This chapter delves even deeper into WHERE clauses and<br />

looks at some of the more sophisticated stuff not covered in Chapter 2.<br />

To recap briefly, the WHERE clause allows you to set one or more conditions that must be satisfied by each<br />

record before it can form part of the results. So if you were asked for a list of members who live in Big<br />

City, you would need to specify that the column City must be equal to Big City. The <strong>SQL</strong> for such a<br />

request appears below:<br />

SELECT FirstName + ‘ ‘ + LastName AS [Full Name]<br />

FROM MemberDetails<br />

WHERE City = ‘Big City’;<br />

The query provides the following results:<br />

Full Name<br />

John Jackson<br />

Jack Johnson<br />

You can also use the operators you saw in Chapter 2 to find out the names of all the films released before<br />

1977:<br />

SELECT FilmName<br />

FROM Films<br />

WHERE YearReleased < 1977<br />

This query gives these results:<br />

FilmName<br />

On Golden Puddle<br />

Planet of the Japes<br />

The Maltese Poodle<br />

Soylent Yellow<br />

However, if you want to find out which films were released in or before 1977, then change the “less<br />

than” operator (

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

Saved successfully!

Ooh no, something went wrong!