SELECT t1.*, (SELECT COUNT(*) FROM table_name t2 WHERE t2.id <= t1.id) AS row_num FROM table_name t1 ORDER BY t1.id;