开发者

Get max one result of each value in a column

I'm working with a Informix DB and with a table like this:

Col1 Col2 Col3
a    a    a
b    a    c
c    b    a
d    c    d

Is it possible from the SQL statement to just display ONE of the first 2 rows by just specify only unique results (values can be anything). I only want one result from col2 with the same value and I 开发者_如何学Pythondon't mind which one of the lines being retrieved.

I hope I'm making sense.


Assuming you have a tie-breaking column (a single-column primary key), you could use something like this

select t.*
from (
    select col2, min(pk_id) pk_id
    from tbl
    group by col2
) x, tbl t
where t.col2=x.col2 and t.pk_id=x.pk_id
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜