Reputation: 97
I have a table as below:
id value
-------------------------
1 1
5 1
7 1
8 4
I can't get to table as below:
id value
-------------------------
1 1
8 4
The SQL is
select id,value from table_1 group by id_a
Upvotes: 0
Views: 151
Reputation: 3
In order to use a group by expression, you must have one or more aggregating functions: count, min, max, sum, avg etc. These functions operate on a group of rows at a time. Now when you use an aggregate function with a none aggregated column(s) you need to use the group by clause.
The below will give you the correct answer:
select min(id) id, value from table_1 group by value
Upvotes: 0
Reputation: 13139
Try this:
select min(id), id_a from table_1 group by id_a
Upvotes: 0
Reputation: 270617
All you have here is a simple MIN()
aggregate.
SELECT MIN(id), value AS id FROM table_1 GROUP BY value
Upvotes: 2