Win a copy of Svelte and Sapper in Action this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Examples of Partition, Row Over to find duplicate queries

 
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

-- Here i wanted to find out rows that have duplicate values in 2 columns, and find out the lesser id on these 2 rows.
select * from (SELECT ROW_NUMBER() OVER (PARTITION BY col1, col2 ORDER BY colid DESC) as row_number,
colid, col1, col2, col3, col4 from <some table> ) where row_number = 2;


-- here i wanted to find out latest bonds records a history table that tracks various status that a bond can have.
select a.bond_key, a.bond_status_tp_cd, a.status_date, a.maximum_date from
(select bond_key, bond_status_tp_cd, status_date, max(status_date)
OVER (PARTITION BY bond_key) as maximum_date from oltp.bond_status_history) a ,
oltp.bond b where b.bond_key = a.bond_key and a.status_date = a.maximum_date and b.IBL_CREATN_IND = 'Y' and a.bond_status_tp_cd in ('25', '100','110','109');


 
They gave me pumpkin ice cream. It was not pumpkin pie ice cream. Wiping my tongue on this tiny ad:
the value of filler advertising in 2020
https://coderanch.com/t/730886/filler-advertising
    Bookmark Topic Watch Topic
  • New Topic