SELECT *, CASE WHEN `sub_cat`= "user cars" AND `cat` = "shopping" AND `locality` = "duncanville" THEN 7 WHEN `sub_cat` IS NULL AND `cat` = "automotive" AND `locality` = "duncanville" THEN 6 WHEN `sub_cat` IS NULL AND `cat` IS NULL AND `locality` = "duncanville" THEN 5 WHEN `sub_cat` IS NULL AND `cat` IS NULL AND `locality` IS NULL THEN 0 END as `rank` FROM `wp_37_slides` WHERE (locality = "duncanville" OR locality IS NULL) AND (cat = "automotive" OR cat IS NULL) AND (sub_cat = "user cars" OR sub_cat IS NULL) ORDER BY `rank` DESC LIMIT 20 [15] matching rows / [0.00 msec] Blog ID 37 Blah
AUTOMOTIVE