sql - Group by with MIN value in same query while presnting all other columns -


i have view called a data:

 id    tdate        name     task   val 23   2015-06-14 23   2015-06-25 126  2015-06-18 126  2015-06-22 126  2015-06-24 

id integer , tdate timestamp.

basically want each id min value of tdate , present row. meaning:

id   tdate       name     task   val 23   2015-06-14 126  2015-06-18 

i wrote query:

select id, min(tdate) group id order id 

this working but doesn't allow me present other columns of a

for example if do:

select id, min(tdate), name group id order id 

it says name must under group by. wrote query:

select id, min(tdate), name, task, val , .... group id, name, task, val , .... order id 

and 1 doesn't work. gives false results.

how solve it?

postgres has convenient distinct on type of problem:

select distinct on (id) a.* order id, tdate; 

this return 1 row each id. row first 1 determined ordering defined in order by clause.


Comments

Popular posts from this blog

android - Gradle sync Error:Configuration with name 'default' not found -

java - Andrioid studio start fail: Fatal error initializing 'null' -

html - jQuery UI Sortable - Remove placeholder after item is dropped -