-1

I have two tables

MappingTable > Id, ItemId, Quantity

ItemTable > ItemId, Name, DateOfPurchase

I wanted to find out the duplicate rows having same Quantity and same DateOfPurchase.

eg. I have 

Id ItemId Quantity
1  01      4
2  03      5
3  05      4

ItemId Name DateOfPurchase
01      AB    2019-10-30 18:30:00
05      XY    2019-10-30 18:17:00

Result:
Quantity DateOfPurchase Name
4        2019-10-30     AB 
4        2019-10-30     XY 

So, I might join these tables and then find duplicates

How can I do that?

GMB
  • 216,147
  • 25
  • 84
  • 135
Charu
  • 40
  • 4

1 Answers1

1

One option is to use window funtions, if your database supports them:

select *
from (
    select 
        m.*, 
        i.name, 
        i.dateOfPurchase,
        count(*) over(partition by m.quantity, p.dateOfPurchase) cnt
    from mapping m
    inner join item i on i.itemId = m.itemId
) t
where cnt > 1
order by quantity, dateOfPurchase
GMB
  • 216,147
  • 25
  • 84
  • 135