[SOLVED] How can i apply group by after applying limit in mysql?

Issue

I am trying to run the below query but it is wrong as per MySQL syntax.
I want to select the first 100 rows then want to apply group by to it.

select customerid from customer
limit 100
group by customerid

How can I achieve it?

Solution

How about this? You need to add an aggregation column for it to work.

SELECT customerid
FROM   (SELECT *
        FROM   customer
        LIMIT  100) sub1
GROUP  BY sub1.customerid; 

Answered By – Darshit Parmar

Answer Checked By – Candace Johnson (BugsFixing Volunteer)

Leave a Reply

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