PostgreSQL Sorting Rows
$count++; if($count == 1) { #include "../mobilemenu.php"; } if ($count == 2) { include "../sharemediasubfolder.php"; } ?>
We can use ORDER BY command to sort rows in PostgreSQL.
SELECT * FROM Planet ORDER BY NAME;
The above command will sort the planets by NAME in Ascending order.
cosmos=# SELECT * FROM Planet ORDER BY NAME;
name | galaxyname | numberofmoons | weight | creation
---------+------------+---------------+--------+------------
Earth | MilkyWay | 1 | 130000 | 0800-03-15
Jupiter | MilkyWay | 21 | 20000 | 1001-01-02
Mercury | Andromeda | 0 | 100 | 1300-01-03
Pluto | MilkyWay | 0 | 100 | 0900-03-15
(4 rows)
To sort by Descending order, type DESC after your SQL Command.
SELECT * FROM Planet ORDER BY NAME DESC;
The above command will sort the planets by NAME in Descending order.
cosmos=# SELECT * FROM Planet ORDER BY NAME DESC;
name | galaxyname | numberofmoons | weight | creation
---------+------------+---------------+--------+------------
Pluto | MilkyWay | 0 | 100 | 0900-03-15
Mercury | Andromeda | 0 | 100 | 1300-01-03
Jupiter | MilkyWay | 21 | 20000 | 1001-01-02
Earth | MilkyWay | 1 | 130000 | 0800-03-15
(4 rows)