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.

YearReleased<br />

1984<br />

1980<br />

1977<br />

1975<br />

1967<br />

1967<br />

1967<br />

1947<br />

Because ascending order is the default for ORDER BY, specifying ascending order is not necessary in the<br />

<strong>SQL</strong>, but for completeness, adding ASC after the ORDER BY clause ensures that results display in ascending<br />

order:<br />

SELECT YearReleased<br />

FROM Films<br />

ORDER BY YearReleased ASC;<br />

The column used to order the results, however, doesn’t have to form part of the results. For example, in<br />

the following <strong>SQL</strong>, the SELECT statement returns the FilmName and Rating, but the YearReleased column<br />

determines order:<br />

SELECT FilmName, Rating<br />

FROM Films<br />

ORDER BY YearReleased;<br />

The preceding <strong>SQL</strong> produces the following results:<br />

FilmName Rating<br />

The Maltese Poodle 1<br />

On Golden Puddle 4<br />

Soylent Yellow 5<br />

Planet of the Japes 5<br />

One Flew over the Crow’s Nest 2<br />

The Lion, the Witch, and the Chest of Drawers 1<br />

Raging Bullocks 4<br />

The Life of Bob 1<br />

The Dirty Half Dozen 2<br />

Extracting Information<br />

Table continued on following page<br />

77

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

Saved successfully!

Ooh no, something went wrong!