Java Reference
In-Depth Information
When there is more than one column in the
select
clause, the
distinct
keyword applies
to the whole tuple in the result. For example, the following statement displays all tuples with
distinct
subjectId
and
title
, as shown in FigureĀ 32.16. Note that some tuples may have
the same
subjectId
but different
title
. These tuples are distinct.
select distinct
subjectId, title
from
Course;
F
IGURE
32.16
The keyword
distinct
applies to the entire tuple.
32.3.11 Displaying Sorted Tuples
SQL provides the
order by
clause to sort the output using the following syntax:
select
column-list
from
table-list
[
where
condition]
[
order by
columns-to-be-sorted];
In the syntax,
columns-to-be-sorted
specifies a column or a list of columns to be sorted.
By default, the order is ascending. To sort in a descending order, append the
desc
keyword.
You could also append the
asc
keyword after
columns-to-be-sorted
, but it is not neces-
sary. When multiple columns are specified, the rows are sorted based on the first column, then
the rows with the same values on the first column are sorted based on the second column, and
so on.
Query 6:
List the full names of the students in the CS department, ordered primarily on
their last names in descending order and secondarily on their first names in ascending order.
The query result is shown in FigureĀ 32.17.
F
IGURE
32.17
You can sort results using the
order by
clause.
Search WWH ::
Custom Search