sql - Get Unique Results in a query -
im sure pretty simple t-sql guru.
i have following result table
idmain idsecondary textvalue 1 1 text1 1 2 text2 2 5 text3 2 6 text5
and want obtain first occurence of idmain only.
the result should this.
idmain idsecondary textvalue 1 1 text1 2 5 text3
how can achieve this?
you should able join sub query, in following example. assumes "first" mean lowest idsecondary
:
select t.idmain, sub_t.minsecondary, t.textvalue your_table t join (select idmain, min(idsecondary) minsecondary your_table group idmain) sub_t on (sub_t.idmain = t.idmain);
Comments
Post a Comment