33

I have used the following SQL, and it's working fine, but I need to sort empty strings also. Please give me guidance on this.

SELECT id, first_name, last_name 
FROM users
ORDER BY first_name DESC NULLS LAST
limit 10;

2 Answers 2

47

Use some conditional functions, e.g.

ORDER BY NULLIF(first_name, '') DESC NULLS LAST
Sign up to request clarification or add additional context in comments.

Comments

1

ORDER BY IF( first_name = '' OR first_name IS NULL,1,0), first_name;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.