SELECT *, CASE WHEN `sub_cat`= "salvage" AND `cat` = "automotive" AND `locality` = "duncanville" AND `logo_file_name` IS NOT NULL THEN 10 WHEN `sub_cat`= "salvage" AND `cat` = "automotive" AND `locality` = "duncanville" AND `logo_file_name` IS NULL THEN 9 WHEN `sub_cat`= "salvage" AND `cat` = "automotive" AND `locality` IS NULL AND `logo_file_name` IS NOT NULL THEN 10 WHEN `sub_cat`= "salvage" AND `cat` = "automotive" AND `locality` IS NULL AND `logo_file_name` IS NULL THEN 9 WHEN `sub_cat` IS NULL AND `cat` IS NULL AND `locality` = "duncanville" AND `logo_file_name` IS NOT NULL THEN 2 WHEN `sub_cat` IS NULL AND `cat` IS NULL AND `locality` = "duncanville" AND `logo_file_name` IS NULL THEN 1 WHEN `sub_cat` IS NULL AND `cat` IS NULL AND `locality` IS NULL AND `logo_file_name` IS NULL THEN 0 END as `rank` FROM `wp_37_slides` WHERE (locality IN ("duncanville") OR locality IS NULL) AND (cat = "automotive" OR cat IS NULL) AND (sub_cat = "salvage" OR sub_cat IS NULL) AND active = 1 ORDER BY `rank` DESC LIMIT 20 [11] matching rows / [0.00 msec] Blog ID 37 Blah
AUTOMOTIVE