SELECT SQL_CALC_FOUND_ROWS IF (F.`CategoryId1` = 8183, F.`CategoryRank1`, IF (F.`CategoryId2` = 8183, F.`CategoryRank2`, IF (F.`CategoryId3` = 8183, F.`CategoryRank3`, IF (F.`CategoryId4` = 8183, F.`CategoryRank4`, IF (F.`CategoryId5` = 8183, F.`CategoryRank5`, IF (F.`CategoryId6` = 8183, F.`CategoryRank6`, IF (F.`CategoryId7` = 8183, F.`CategoryRank7`, 0))))))) AS Rank, F.* FROM Firm F WHERE F.AreaId = 180 AND ( F.CategoryId1 = 8183 OR F.CategoryId2 = 8183 OR F.CategoryId3 = 8183 OR F.CategoryId4 = 8183 OR F.CategoryId5 = 8183 OR F.CategoryId6 = 8183 OR F.CategoryId7 = 8183) ORDER BY Rank DESC LIMIT 0, 20 Big finds from small businesses | 2FINDLOCAL.COM