Sample Header Ad - 728x90

Sort by multiple columns, using nulls first on one of them

0 votes
2 answers
1461 views
Given a members table, having the following columns: accepted_at datetime , updated_at datetime NOT NULL Given this query: select * from members order by accepted_at DESC NULLS FIRST, updated_at DESC We invariably always want accepted_at IS NULL at the beginning of the list, then the most recent members updated following in the list. The above query prioritizes on the updated_at column, so I end up with accepted members at the beginning of list.
Asked by Ben (179 rep)
Feb 8, 2023, 10:49 AM
Last activity: May 13, 2024, 02:58 PM