I have a table with 2 columns:
| Product | Received |
|---|---|
| a | 01-01-2022 |
| a | |
| b | |
| c | 20-01-2022 |
| c | |
| d |
I need to create a query that will hide duplicates on the "Product" column, if there´s aleready a record that contains that procuct and also a date in the "Recieved" column.
To get this result:
| Product | Received |
|---|---|
| b | |
| d |
Can anyone help me with this?
Thank you.
CodePudding user response:
Here is a query using GROUP BY and testing the condition in the HAVING clause, i.e., after grouping
SELECT prod.Product, Max(prod.Received) AS MaxOfReceived, count(*) as cnt
FROM prod
GROUP BY prod.Product
HAVING Max(prod.Received) Is Null OR count(*) = 1;
It lists all products either having no Received date or having only one record.
