Given the tables in MySQL 5.0:
clients
=======
id int
users
=====
id int
client_id int
is_primary tinyint
A client can have many users. I want to update users.is_primary = 1 for only the smallest users.id per users.client_id
For example, given these users:
users
id client_id is_primary
============================
1 1 0
2 1 0
3 2 0
4 2 0
5 3 0
I want to end up with:
users
id client_id is_primary
============================
1 1 1
2 1 0
3 2 1
4 2 0
5 3 1
Is there a way to write an update statement to do so?
1 Answer