-2

I have a large table as dataset. If there are 2 similar rows with same date and id then how do I get the row for which another column value is not null?

SELECT *, row_number() 
   over (partition by id order by date desc) rowNumber 
FROM table where rowNumber = 1;
Rory McCrossan
  • 331,213
  • 40
  • 305
  • 339
MKM
  • 1
  • 2
  • Why did you think row number a solution to this , I would have thought a not null test on ciol2 would suffice. Sample data and expected outcome as text would help clarify. – P.Salmon Sep 19 '22 at 12:32
  • Hi, there are multiple rows initially for a single id, get the latest dated row for a particular id because eventually I need one row with latest timestamp. But incase there are duplicate after that filter for same time value then get the row for which col2 is non null – MKM Sep 20 '22 at 03:22

2 Answers2

0

Please try this query:

select * from table where (id, date) in 
(select id, date from table group by id, table having count(1) > 1) 
and value is not null;
Pralhad K
  • 11
  • 1
0

Ordering by the column which has 2 values(1 row with null and 1 without null) helped

default ordering is ascending and NULLS LAST is the default for ascending order and rowNumer=1 would give the row without null

MKM
  • 1
  • 2