I want to query only the data which don't have any Previous Transaction
This is the Query Result
sku barcode details load_dt
546 a674 testabc2 2021-10-21
546 a674 testabc2 2021-10-17
111 a111 test1111 2021-10-21
111 a111 test1111 2021-10-20
333 a333 test3333 2021-10-21
444 a444 test4444 2021-10-21
Expected Result
sku barcode details load_dt
333 a333 test3333 2021-10-21
444 a444 test4444 2021-10-21
CodePudding user response:
You can use GROUP BY
and HAVING
to filter data that has only 1 row
SELECT * FROM trans WHERE sku IN (
SELECT sku
FROM trans
GROUP BY sku
HAVING COUNT(*) = 1)
Here, I create dbfiddle