I have a table that looks something like this:
customer_id | data |
---|---|
1 | 123 |
1 | 456 |
2 | 789 |
2 | 101 |
2 | 121 |
2 | 123 |
3 | 123 |
4 | 456 |
What I would like to do is perform a SELECT
combined with a LIMIT X
to get X number of records as well as any other records that have the same customer_id
Example query: SELECT customer_id, data FROM table ORDER BY customer_id LIMIT 3;
This query returns:
customer_id | data |
---|---|
1 | 123 |
1 | 456 |
2 | 789 |
I'd like a query that will look at the last customer_id
value and return all remaining records that match beyond the LIMIT
specified. Is it possible to do this in a single operation?
Desired output:
customer_id | data |
---|---|
1 | 123 |
1 | 456 |
2 | 789 |
2 | 101 |
2 | 121 |
2 | 123 |