Categories
MySQL

MySQL custom row number in a result set

You can add a sequential number as a custom row number of a row using SET clause and increment at next row.

Suppose users table has columns name and age.
When you want to show the result you want to add extra column serial_no.

You may like:  MySQL UPDATE Statement

So using below query you can achieve custom row number:

SET @serial_number = 0;

SELECT
(@serial_number:=@serial_number + 1) AS serial, name, age
FROM
users
LIMIT 0,50;
Serial noNameAge
1John25
2Jane24
3Tim34
Avatar for Namaste UI (Author)

By Namaste UI (Author)

Namaste UI collaborates closely with clients to develop tailored guest posting strategies that align with their unique goals and target audiences. Their commitment to delivering high-quality, niche-specific content ensures that each guest post not only meets but exceeds the expectations of both clients and the hosting platforms. Connect with us on social media for the latest updates on guest posting trends, outreach strategies, and digital marketing tips. For any types of guest posting services, contact us on info[at]namasteui.com.

Leave a Reply

Your email address will not be published. Required fields are marked *