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