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