This question already has an answer here:
- Select first row in each GROUP BY group? 14 answers
I have this table:
Is there a way to group by the key to get this result?
Or this result:
If I use this query:
Group by query with multiple columns. Please help me any one know about this. Friday, February 22, 2013 7:34 PM. If you are using any aggregate function in your select statement then you an use group by clause, the column on which you will do group by must be present in your select statement, your query seems to be OK. Sep 27, 2015 'Group By' clause is used for getting aggregate value (example: count of, sum of) in one or more columns with reference to a distinct column in a table. 'Order By' clause is used to sort the resulting rows in the order of specified column or colum.
This is not correct I know that, because I should group by all the columns that I need to show.
Is there a solution for this problem?
YCF_LYCF_L
marked as duplicate by Erwin Brandstetter postgresqlOct 2 '16 at 13:21
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
2 Answers
Notice that the
order by
clause determines which row will win the ties.Clodoaldo NetoClodoaldo Neto
A query that works for all DB engines would be
where
min(id)
is the function that influences which result you get. If you use max(id)
you get the other.juergen djuergen d