title: How to get unique values from two different tables?
body: <p>I've two tables: T1 &amp; T2. My column of interest are 'Item' from T1 &amp; 'Store' from T2.</p>
  <p>Here's my query &amp; few options i've tried but could get desired result:</p>
  <pre><code>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
  
  
  </code></pre>
  <p>I am trying to get unique row values for both column</p>
  <p>Here's the scenario i'm facing:
  After doing distinct im getting result as below:</p>
  <pre><code>Item Store
  1     8
  2     8
  3     8
  </code></pre>
  <p>But my desired result is (1 item per store):</p>
  <pre><code>Item Store
  1     8
  2     15
  3     53
  </code></pre>
  <p>That is, It should be unique for all rows but i am unable to achieve it. Please suggest.</p>
  <p><strong>EDIT:</strong></p>
  <p>Table T1:</p>
  <pre><code>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  
  
  
  </code></pre>
  <p>Table T2:</p>
  <pre><code>Store      ITEM_ID      Itemsale       Status   
  8          1             (null)          C      
  65         87            (null)          C      
  
  </code></pre>
  <p><strong>Solution for my case</strong></p>
  <pre><code>**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**
  </code></pre>