MySQL Forums
Forum List  »  Newbie

Select all the rows that fulfill the criteria: only the first 2 occurences of a value in column B
Posted by: Cristian Tanasa
Date: April 23, 2021 10:33PM

Dear all,

Could please someone help out?
It is quite difficult to describe what I need:
Select all the rows that fulfill the criteria: only the first 2 occurences of a value in column B.
Therefore I conceived the example below:

I would need a query that would yield as results the entire rows 1, 2, 5, 6, 7.
= the query should check column B and select only 2 rows for the customer 55555. Which rows are selected is not relevant: it could be also 3 and 4.
Important is, that not more than 2 rows for each customer are selected. Some customers have only one occurence (customer 88888) - for these should be selected only this available row.

Many thanks for your help,
Cristian

Nr. Cust. OrderID ProdID Quantity
1 55555 10248 11 12
2 55555 10249 42 10
3 55555 10250 72 5
4 55555 10251 14 9
5 88888 10252 51 40
6 44444 10253 56 11
7 44444 10254 33 45
8 55555 10255 74 22

Options: ReplyQuote




Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.