Database Reference
In-Depth Information
Figure 4.6
A filtered query.
4.2.3
Sorted Query
Now let's sort. Figure 4.5 shows artists listed by their ARTIST_ID. The
order in Figure 4.5 is not because of a unique key but because that is the
order in which rows were inserted. Without an ORDER BY clause, the
sorted order of a query depends on columns selected and other criteria such
as the WHERE clause. Using the ORDER BY clause, Figure 4.7 shows art-
ists re-sorted in the order of their names (the NAME column values). Now,
the numbers in the ARTIST_ID column appear out of order.
SELECT ARTIST_ID, NAME FROM ARTIST ORDER BY NAME ;
4.2.4
Grouping or Aggregated Query
Now let's do a grouping. The COUNT function in this example causes an
aggregate or group on the COUNTRY column. The results are displayed in
Figure 4.8 summary rows: one for each unique value found in the COUN-
TRY column.
SELECT COUNT(COUNTRY) , COUNTRY FROM ARTIST GROUP BY COUNTRY ;
 
Search WWH ::




Custom Search