Skip to content
Advertisement

SQL – Ordering query by lastest date and then by ID

I have a table that looks something like this:

I want it to be ordered by the CreatedOn field and then NotificationTypeID like this:

My SQL looks like this:

But it gives me the oldest value first:

Advertisement

Answer

I suspect that you want:

This will put first the NotificationTypeID that has the greatest CreatedOn, and then order records that have the same NotificationTypeID by descending CreatedOn.

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement