How do I avoid a filesort when I want to order a query by condition in MySQL?
ORDER BY (videos_count > 0) DESC, name
Would it be better to cache a has_videos boolean column as well as the count?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
How about partitioning the query into two, first the ones with at least one video, then (only if needed) the rest:
And if you need to go beyond those: