Hitachi

Hitachi Advanced Database SQL Reference


1.3.2 Example 2: Sort retrieval results by date of purchase and customer ID

Sort all of the data in the sales history table (SALESLIST) by date of purchase (PUR-DATE). In cases where the date of purchase is the same, order by customer ID (USERID). The sales history table consists of columns for customer ID (USERID), product code (PUR-CODE), quantity purchased (PUR-NUM), and date of purchase (PUR-DATE).

Table to search

[Figure]

Specification example
SELECT "USERID","PUR-CODE","PUR-NUM","PUR-DATE"
    FROM "SALESLIST"
    ORDER BY "PUR-DATE" ASC,"USERID" ASC
Retrieval results

[Figure]

Note

You can specify multiple columns in the ORDER BY clause. The column that is specified first is given highest priority in the ordering. In this example, results are first ordered by date of purchase (PUR-DATE), and then ordered by customer ID (USERID) in cases where the date of purchase is the same.