Skip to content
Advertisement

Self Join : How to select a specific set of data

I have a simple table with data as

enter image description here

As we can see that row 1 & 2 contains exact same ColumnA, ColumnB & ColumnC. I want to form a simple select that can ignore the ‘N’ values where we already have a yes, so something like

enter image description here

I tried using self join but guess not using it right or likely not using the right thing.

Can someone drop a little suggestion here?

This is what I am trying

Advertisement

Answer

I suggest using the window function row_number() to accomplish this. So its partitioning by the columns you want to compare, and ordering by the preferred result

Returns:

Note the data displayed as formatted text, and the DDL/DML statements to setup test data.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement