Is it possible to adapt LIMIT to specific columns?
As an example, I would like to extract two records with the same id, assuming the following data is available.
data for:
Desired Results:
*If id=3000, there are no more than two records with the same id, so I would like to display just one record as above without excluding it.
mysql sql
ROW_NUMBER()
is available for MySQL 8.0, so
MySQL 8.0 Reference Manual::12.21.1 Window Function Descriptions
You can write as follows:
SELECT no, id, name FROM(
SELECT*, ROW_NUMBER() OVER(PARTION BY ID ORDER BY NO) as ranking
FROM member
AS_WHERE ranking <=2;
© 2024 OneMinuteCode. All rights reserved.