Ordey by multiple expressions
Syntax is:
select * from <TABLE> ORDER BY <COL NAME> ASC|DEC, <COL NAME> ASC|DEC, <COL NAME> ASC|DEC .... and so on.
Example below:
postgres=# select * from editions;
isbn | book_id | edition | publisher_id | date | type
------------+---------+---------+--------------+-------------+------
039480001X | 1608 | 1 | 59 | 1957-03-01 | h
0451160916 | 7808 | 1 | 75 | 1981-08-01 | p
0394800753 | 1590 | 1 | 59 | 1949-03-01 | p
0590445065 | 25908 | 1 | 150 | 1987-03-01 | p
0694003611 | 1501 | 1 | 65 | 1947-03-04 | p
0679803335 | 1234 | 1 | 102 | 1922-01-01 | p
(6 rows)
postgres=#
postgres=# -- Using ORDER BY with multiple expressions
postgres=#
postgres=# SELECT edition, publication
postgres-# FROM editions
postgres-# ORDER BY edition ASC,
postgres-# date DESC;
edition | publication
---------+-------------
1 | 1987-03-01
1 | 1981-08-01
1 | 1957-03-01
1 | 1949-03-01
1 | 1947-03-04
1 | 1922-01-01
(6 rows)
|