nevvermind
nevvermind

Reputation: 3392

Conditional GROUP BY result

I need the query to group by name and, if one of the is_new is 1, the resulting value should be 1.


Current rows:

+--------+--------+
| name   | is_new |
+--------+--------+
| a      |      0 |
| a      |      0 |
+--------+--------+
| b      |      0 |
| b      |      1 |
+--------+--------+
| c      |      1 |
| c      |      1 |
+--------+--------+

Expected query result:

+--------+--------+
| name   | is_new |
+--------+--------+
| a      |      0 |
| b      |      1 |
| c      |      1 |
+--------+--------+

Upvotes: 2

Views: 452

Answers (1)

rabudde
rabudde

Reputation: 7722

SELECT name,MAX(is_new) AS is_new FROM <TABLE> GROUP BY name

Upvotes: 6

Related Questions