postgresql select minimum from a value pair of two columns -


i have table looks this:

id | group | title | description | added | modified --------------------------------------------------- 1  |   1   |  ...  |     ...     |  ...  |   ... 2  |   1   |  ...  |     ...     |  ...  |   ... 3  |   2   |  ...  |     ...     |  ...  |   ... 4  |   2   |  ...  |     ...     |  ...  |   ... 5  |   3   |  ...  |     ...     |  ...  |   ... 

now need select first row of every group value. think using distinct keyword kind of right direction here. using:

select distinct group table; 

obviously return group values, not remaining fields:

group -----   1   2   3 

does know how accomplish this?

what i'm looking - in regard above example - kind of output:

id | group | title | description | added | modified --------------------------------------------------- 1  |   1   |  ...  |     ...     |  ...  |   ... 3  |   2   |  ...  |     ...     |  ...  |   ... 5  |   3   |  ...  |     ...     |  ...  |   ... 

thanks in advance!!

select mk.* meuk mk join ( select zgroup, min(id) id         meuk         group zgroup         ) agg on agg.id = mk.id         ; 

or one:

select * meuk mk not exists ( select  *         meuk nx         nx.zgroup = mk.zgroup         , nx.id < mk.id         )         ; 

Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -