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

Castle Pines North