1

I am trying to delete the duplicate rows based on two columns. An example for table as below

Table Name as REFF_TABLE

LOCATIONID  TICKER  ROW_KEY
AB            PA    201605
AB            PA    201605
AB            PA    201606
AB            PA    201606
DA            PB    201705
DA            PB    201706
DA            PB    201707
DE            PC    201808
DE            PC    201809

I want to remove duplicates rows by considering two columns - LOCATIONID, TICKER . Here need to take maximum value of ROW_KEY

Final output table as below

LOCATIONID  TICKER  ROW_KEY
AB            PA    201606
DA            PB    201707
DE            PC    201809

Please help me to solve this

Py1996
  • 219
  • 1
  • 15
  • What have you tries so far? Where did you get stuck? – demircioglu May 27 '21 at 17:21
  • Hope this post from 2015 on StackOverflow helps: https://stackoverflow.com/questions/30243945/removing-duplicate-rows-based-on-values-from-multiple-columns-from-sql-table/30244183 – FKayani May 27 '21 at 17:25

1 Answers1

2

A typical SQL GROUP BY should be enough:

select locationid, ticker, max(row_key) row_key
from table
group by locationid, ticker
Felipe Hoffa
  • 54,922
  • 16
  • 151
  • 325