sql - How to select distinct rows with respect to only certain columns? -
i'm using select below.
select a.bada, b.boom, ' ' '---', * ...
there's bunch of joins along way , have data need but rows repeated respect bada , boom. not exact duplicates because values brought in star differ. however, not relevant case.
the solution i'm applying listing interesting columns explicitly wonder of there's smooth way eliminate rows have bada , boom repeated (keeping 1 occurrence of such row).
most databases support ansi standard window , ranking functions. such, can choose particular or arbitrary rows in set rows same values in columns:
select t.* ( select t.bada, t.boom, row_number() on (partition bada, boom order bada) seqnum, t.*, table t) t seqnum = 1;
this works first adding sequence number of each row over partition of original table. row number consecutive respect selected columns. once that's done, it's possible pick value of consecutive counter, e.g. 1.
select t.bada, t.boom, row_number() on (partition bada, boom order bada) seqnum, t.*, table t
if want particular row -- such recent 1 -- adjust order by
row.
Comments
Post a Comment