How to solve the issue when MySQL row_number() cannot be used?

MySQL does not provide a built-in ROW_NUMBER() function, but it can be simulated using variables to achieve the functionality of ROW_NUMBER().

Here is an example query demonstrating how to use variables to achieve the functionality of ROW_NUMBER().

SET @row_number := 0;
SELECT (@row_number:=@row_number + 1) AS row_number, column1, column2
FROM your_table;

In this query, we first set a variable @row_number to 0 before the query and then simulate the functionality of ROW_NUMBER() by incrementing the value of @row_number and returning it as a column.

Please replace “your_table” in the above query with the actual table name you are using, and select the columns to be returned as needed.

Leave a Reply 0

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


广告
Closing in 10 seconds
bannerAds