SELECT *, CASE WHEN `sub_cat` IS NULL AND `cat` = "" AND `locality` = "AVE MARIA" THEN 6 WHEN `sub_cat` IS NULL AND `cat` IS NULL AND `locality` = "AVE MARIA" THEN 5 WHEN `sub_cat` IS NULL AND `cat` IS NULL AND `locality` IS NULL THEN 0 END as `rank` FROM `wp_4_slides` WHERE (locality = "AVE MARIA" OR locality IS NULL) AND (cat IS NULL) ORDER BY `rank` DESC LIMIT 20 [5] matching rows / [0.00 msec] Blog ID 4 Blah

Ave Maria