I’m trying to implement a LIMIT OFFSET query using MS SQL for the purpose of implementing Pagination to my products on a website together with PHP and PDO, but I get the following error: “Invalid column name”
My query
SELECT OITM.ItemCode,OITM.ItemName,ITM1.Price ,
OITM.CardCode,ROW_NUMBER() OVER (ORDER BY OITM.ItemName DESC) AS RNumber
FROM OITM INNER JOIN OCRD ON OCRD.CardCode = OITM.CardCode
INNER JOIN ITM1 ON OITM.ItemCode = ITM1.ItemCode
WHERE OITM.frozenFor='N' AND PriceList=1 AND U_Publish='Y'
AND RNumber >= 1 AND RNumber <= 2
Not to sure what is wrong here
You do not need a
HAVINGclause. You can use a cte function or a subquery. Like this:Or with a subquery like this: