ORDER BY / GROUP BY on two columns with postgreSQL
Moderator: General Moderators
ORDER BY / GROUP BY on two columns with postgreSQL
Does anybody know the proper SQL to make a select statement that is sorted on two colums. That is columnA first and columnB second? 
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
Not a postgreSQL user (but there are a few of them about so I'm sure they'll correct this if it's way off the mark) but maybe it's similar to things like MySQL where to sort on two columns you would do something like:
Mac
Code: Select all
SELECT field1, field2, field3, field4 FROM table ORDER BY field1, field2- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
yeah and mysql is one of those that do several things very different than many others.. Main differences when it comes to the ORDER BY clause itself is if the RDBMS supports sorting on aliases or not, so it is always better to assume not..
e.g. this may work on some
SELECT (x+y) AS n FROM beer ORDER BY n ASC
but it will work on most (all?) with
SELECT (x+y) AS n FROM beer ORDER BY (x+y) ASC
e.g. this may work on some
SELECT (x+y) AS n FROM beer ORDER BY n ASC
but it will work on most (all?) with
SELECT (x+y) AS n FROM beer ORDER BY (x+y) ASC
Most RDBMS has quite a bit of the SQL92 functionality, but most of them also has their own extensions and may lack a few things, and, several things that are not defined in SQL92 they have made their own flavor of..
I think that PostgreSQL is probably the one that strive the most to be SQL92, and in the future, SQL99 compliant and incorporate more and more of the functionality described in the standards..
I think that PostgreSQL is probably the one that strive the most to be SQL92, and in the future, SQL99 compliant and incorporate more and more of the functionality described in the standards..