Java Reference
In-Depth Information
SELECT AuthorID, FirstName, LastName
FROM Authors
ORDER BY LastName, FirstName
sorts all the rows in ascending order by last name, then by first name. If any rows have the
same last-name value, they're returned sorted by first name (Fig. 24.17).
AuthorID
FirstName
LastName
3
Abbey
Deitel
2
Harvey
Deitel
1
Paul
Deitel
5
Michael
Morgano
4
Dan
Quirk
Fig. 24.17 | Sample data from Authors in ascending order by LastName and FirstName .
Combining the WHERE and ORDER BY Clauses
The WHERE and ORDER BY clauses can be combined in one query, as in
SELECT ISBN, Title, EditionNumber, Copyright
FROM Titles
WHERE Title LIKE '%How to Program'
ORDER BY Title ASC
which returns the ISBN , Title , EditionNumber and Copyright of each book in the Titles
table that has a Title ending with "How to Program" and sorts them in ascending order
by Title . The query results are shown in Fig. 24.18.
ISBN
Title
EditionNumber
Copyright
0133764036
Android How to Program
2
2015
013299044X
C How to Program
7
2013
0133378713
C++ How to Program
9
2014
0132151006
Internet & World Wide Web How to Program
5
2012
0133807800
Java How to Program
10
2015
0133406954
Visual Basic 2012 How to Program
6
2014
0133379337
Visual C# 2012 How to Program
5
2014
0136151574
Visual C++ 2008 How to Program
2
2008
Fig. 24.18 | Sampling of books from table Titles whose titles end with How to Program in
ascending order by Title .
24.4.4 Merging Data from Multiple Tables: INNER JOIN
Database designers often split related data into separate tables to ensure that a database does
not store data redundantly. For example, in the books database, we use an AuthorISBN table
to store the relationship data between authors and their corresponding titles. If we did not
separate this information into individual tables, we'd need to include author information
with each entry in the Titles table. This would result in the database's storing duplicate au-
 
 
Search WWH ::




Custom Search