I've two tables: T1 & T2. My column of interest are 'Item' from T1 & 'Store' from T2.
Here's my query & few options i've tried but could get desired result:
Query1: (very time consuming - Its oracle DB)
select distinct T1.Item,T2.Store from
(select distinct * from T1) T1
full outer join
(select distinct * from T2)T2
on T1.ITEM_ID=T2.ITEM_ID
Query2: (This is so close to the result I need but i'm stuck with max of item value instead of the whole picture)
select max(T1.ITEM),T2.Store from T1 , T2
where T1.ITEM_ID=T2.ITEM_ID
group by T2.Store
I am trying to get unique row values for both column
Here's the scenario i'm facing: After doing distinct im getting result as below:
Item Store
1 8
2 8
3 8
But my desired result is (1 item per store):
Item Store
1 8
2 15
3 53
That is, It should be unique for all rows but i am unable to achieve it. Please suggest.
EDIT:
Table T1:
ID Item ITEM_ID CREATE_DATE UPDATE_DATE
--------- --------------- --------- ------------------- -------------------
123 8 1 2021-05-21 21:08:14 2021-05-21 21:08:14
15 15 7 2021-05-22 14:15:49 2021-05-22 14:15:49
Table T2:
Store ITEM_ID Itemsale Status
8 1 (null) C
65 87 (null) C
Solution for my case
**select T1.Item,T2.Store
from
(SELECT Item, DENSE_RANK() OVER (ORDER BY Item ) rnk from T1 group by Item ) T1
inner join
(SELECT Store ,DENSE_RANK() OVER (ORDER BY Store ) rnk from T2 group by Store ) T2
on T1.rnk=T2.rnk**