Categories: MySQL

MySQL custom row number in a result set

Share

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.

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 no Name Age
1 John 25
2 Jane 24
3 Tim 34

Recent Posts

Chasing Legends: Legendary Moments in Online Gaming

In the vast digital landscapes of online gaming, legends are born and moments are etched…

46 mins ago

Virtual Thrills: Adventures in Online Gaming

In the ever-evolving landscape of entertainment, online gaming stands out as a realm where imagination…

50 mins ago

Rise to Prominence: Climbing the Ranks in Online Gaming

In the fast-paced world of online gaming, the pursuit of excellence is a journey marked…

56 mins ago

Diversifying your portfolio with short term investment

Understanding the value of investment is an essential component of financial planning. Investing not only…

1 hour ago

Ad ROI 101: Making The Most Out of Your Ad Investment

In today's cutthroat business world, where every cent matters, tracking how well your ad campaigns…

6 hours ago

What Are the Differences Between DIY Headshots and Professional Headshots for Work: A Clear Comparison

In today's digital age, headshots have become essential for personal branding, particularly for professional platforms…

11 hours ago