database:mysql:get_item_position_in_resultset

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;
Enter your comment:
Q W S W J
 
  • database/mysql/get_item_position_in_resultset.txt
  • Last modified: 2019-10-31 09:04
  • (external edit)