Languages
[Edit]
EN

MySql - get row position with SELECT query

1 points
Created by:
Root-ssh
68940

This article is focused about problem how in MySql get row number with each row.

Quick solution:

SELECT 
	(@row_number := @row_number + 1) AS `row_number`,
	`client_id`,
	`creation_time`
FROM `clients`
JOIN (SELECT @row_number := 0) r

Screenshot:

row number with select query - HeidiSQL with MySql
row number with select query - HeidiSQL with MySql

Alternative solution

This approach creates variable outside query.

SET @row_number := 0;
SELECT 
	(@row_number := @row_number + 1) AS `row_number`,
	`client_id`,
	`creation_time`
FROM `clients`
Native Advertising
50 000 ad impressions - 449$
🚀
Get your tech brand or product in front of software developers.
For more information contact us:
Red dot
Dirask - friendly IT community for everyone.

❤️💻 🙂

Join