ORDER BY 2 fields
Is it possible to ORDER BY 2 fields? EG. ORDER BY CREATED_DATE AND UPDATED_DATE
This is so that results get ORDERED BY created_date when there is 开发者_运维百科a new record and also by update_date when an existing record gets updated.
Thanks
If what you mean is "order by UPDATED_DATE if it exists and by CREATED_DATE otherwise", you can use a dedicated function depending on the underlying database. For many DBMSs, it's coalesce(), and in your case:
ORDER BY coalesce(UPDATED_DATE, CREATED_DATE)
Yes, you simply separate the columns you want to order by by a comma
ORDER BY created_date,update_date
Which reads as "order by created_date then by update_date". If that's not what you need, please provide furhter explanation.
ORDER BY CREATED_DATE, UPDATED_DATE
"Multiple sort columns can be specified. The sequence of the sort columns in the ORDER BY clause defines the organization of the sorted result set." From MSDN
精彩评论