Eureka Moment Wiki

One eureka moment at the time

User Tools

Site Tools


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;
database/mysql/get_item_position_in_resultset.txt · Last modified: 2018/10/12 10:14 by tplecko