I was hoping some could point me in the right direction when it comes to having pagination and order by in an SQL query. On our itemmast table I want retrieve the first 15 records and sort them by price DESC. So, ideally when paging through it would show items going from low price items to the highest. Right now, the 1st 15 results look good in regard to price DESC however if I click to the next page it's grabbing the next set of records so it's not actually giving me next result set in order of price DESC. It's just grabbing those next 15 products and sorting them price DESC
Would I need to create of view of the table where it's ordered by pricing DESC?
Here a an example of my current SQL query:
$sql = "SELECT iitem, isell, istats FROM (
SELECT iitem, isell, istats,
ROW_NUMBER() OVER (ORDER BY iitem)
AS RowNum
FROM $schema.itemmast
WHERE istats <> 'V'
AND isell > '0'
AND iitem LIKE '%".db2_escape_string($searchTerm)."%' )
AS Data
WHERE RowNum
BETWEEN $start
AND $end
ORDER BY isell DESC ";
Thanks