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.

SELECT MAX(LastName), MIN(LastName)<br />

FROM MemberDetails<br />

WHERE MemberId > 3;<br />

Executing the code gives the results in the following table:<br />

MAX(LastName) MIN(LastName)<br />

Simons Botts<br />

In the following <strong>SQL</strong>, the MAX() and MIN() functions have been removed, and executing the code will<br />

show only the results set ordered using an ORDER BY clause<br />

SELECT LastName<br />

FROM MemberDetails<br />

WHERE MemberId > 3<br />

ORDER BY LastName;<br />

You can see that MAX(LastName) is simply the last item in the list and MIN(LastName) is the first item<br />

in the list:<br />

LastName<br />

Botts<br />

Dales<br />

Doors<br />

Gee<br />

Hawthorn<br />

Hills<br />

Jackson<br />

Johnson<br />

Jones<br />

Jones<br />

Night<br />

Simons<br />

Grouping and Aggregating Data<br />

You can also see that generally ORDER BY, and therefore MAX() and MIN(), are based on alphabetical order,<br />

although this isn’t always the case, especially when numbers and punctuation appear in strings. The next<br />

Try It Out uses the MAX() and MIN() functions to gather birth dates for the film club’s chairperson.<br />

201

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

Saved successfully!

Ooh no, something went wrong!