Reputation: 1240
this is an example:
table mysql schema :
id name salary 1 david 20 2 jack 30 3 david 10
Query:
$sql = "UPDATE table SET salary = salary + 5 WHERE name = 'david' ";
I want to added Group By name
to avoid duplicate update for david
How Could I do that?
Upvotes: 2
Views: 817
Reputation: 563021
Try using LIMIT, which is an extension to SQL used by MySQL:
$sql = "UPDATE table SET salary = salary + 5 WHERE name = 'david'
ORDER BY id LIMIT 1";
It makes no sense to use GROUP BY, because it would be ambiguous whether to update the first row in the group, or the last row, or all of the rows. MySQL does not support a GROUP BY clause in the UPDATE statement.
Upvotes: 2