If I apply a limit when selecting with group by, the limit is applied to the number of groups returned or the number of rows?
Myself, I want to limit the groups returned.
Here’s my trial:
select * from orders group by customer_email limit 0,2
From this table:
id customer_email
0 a@a.com
1 a@a.com
2 a@a.com
3 b@b.com
4 c@c.com
5 c@c.com
6 d@d.com
I want returned rows 0,1,2,3,4,5.
Your question is a little ambiguous: the proposed query limits to 2 groups, and you seem to want all the rows with equal
customer_emailthat are contained in the first 3 groups.Anyway, here is my answer for as far as I correctly understand your question 🙂
The sub query
select customer_email from orders group by customer_email limit 0,3selects the first 3 groups, then you select all the rows inorderthat contain the samecustomer_emailas in the first 3 groups which would give you row 0, 1, 2, 3, 4, 5.