www.fromthevalley.com.au

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 |       |           59 1957-03-01  | h
 0451160916 |    7808 |       |           75 1981-08-01  | p
 0394800753 |    1590 |       |           59 1949-03-01  | p
 0590445065 |   25908 |       |          150 1987-03-01  | p
 0694003611 |    1501 |       |           65 1947-03-04  | p
 0679803335 |    1234 |       |          102 1922-01-01  | p
(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
---------+-------------
       1987-03-01
       1981-08-01
       1957-03-01
       1949-03-01
       1947-03-04
       1922-01-01
(rows)
          

HOMEAJAXAPACHEBizphoneCSSDNSGeneralGraphicsHTMLHardwareJavascriptLinuxMACMS SQLMailMicrosoftOFFICE 365PerlPostgresSEOSocial MediaVMwareWindows 10