I want to sort according to date first and then if date is similar then according to id..How to do that in Informix/HSQL query?
Asked
Active
Viewed 3.3k times
6 Answers
30
SELECT FIELD1, FIELD2 FROM TABLE ORDER BY FIELD1 ASC, FIELD2 ASC
A good tutorial on this SQL ORDER BY

ChrisBint
- 12,773
- 6
- 40
- 62
3
Try this(adjusted to your needs):
SELECT * FROM table ORDER BY datecol ASC, id ASC

fyr
- 20,227
- 7
- 37
- 53
0
select * from (select * from tablename order by col1) AS T order by col2
This works but is redundant and obtuse. Note the subquery (on "col1") becomes the secondary sort; the primary sort is the encompassing query. Some environments may require the "as T" aliasing of the subquery, but not all.
select * from tablename order by col2, col1
This does the same thing as above, with simple clarity
Or for a more realistic example:
select * from customers order by lastname, firstname

Stephen Ostermiller
- 23,933
- 14
- 88
- 109

davhill
- 1