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