Ered
Ered

Reputation: 497

MYSQL group by for separate id

So here is the structure and query: http://www.sqlfiddle.com/#!9/de7ec8/4

And this is the result:

+-------------+--------+
| id_requests | status |
+-------------+--------+
|           1 |      0 |
|           1 |      0 |
|           1 |      1 |
|           2 |      1 |
+-------------+--------+
4 rows in set

and im looking for this result:

+-------------+--------+
| id_requests | status |
+-------------+--------+
|           1 |      0 |
|           1 |      1 |
|           2 |      1 |
+-------------+--------+
3 rows in set

I want to group by status but for each id_requests, any help will be appreciated.

Upvotes: 2

Views: 65

Answers (1)

ScaisEdge
ScaisEdge

Reputation: 133370

Seems you are looking for selecting distinct rows for this use distinct clause

SELECT distinct a.id_requests, b.status 
FROM `admin_availability_requests` a

Upvotes: 2

Related Questions