I have a table like this:
id description status login XWPggD bbbbbbbb 1 js 0JIERf test1 1 js 0gd2x0 nothing NULL js bSIUIu dev NULL bob 0BNh27 hello 1 js 2TYXjd down NULL inge axE1m5 bobby NULL bob 1iSlQM qwe 0 js 9dPjoP descr NULL inge
I'm trying to sort the output by status(null values at the bottom) and then by login. But I also want the login values, where the status is NULL to be ordered correctly, so that it looks like:
id description status login XWPggD bbbbbbbb 1 js 0JIERf test1 1 js 0BNh27 hello 1 js 1iSlQM qwe 0 js axE1m5 bobby NULL bob bSIUIu dev NULL bob 9dPjoP descr NULL inge 2TYXjd down NULL inge 0gd2x0 nothing NULL js
But when I try something like:
SELECT id, description, status, login FROM dev
ORDER BY isnull(status) ASC, isnull(login) ASC;
I always get a weird loginorder where status values are NULL.
Why so complicated answers ...
SELECT id, description, status, login FROM dev
ORDER BY status IS NULL, status DESC, login IS NULL, login DESC
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments