Get row position in ordered result set (pagination)
SET @val := 0; CREATE TEMPORARY TABLE IF NOT EXISTS inv_items_tmp AS (SELECT (@val := @val + 1) AS val, id FROM inv_items ORDER BY inv_no,model); SET @oneless := (SELECT val FROM inv_items_tmp WHERE id=2977); SELECT COUNT(*) FROM inv_items_tmp WHERE val<@oneless; DROP TABLE inv_items_tmp;