Reputation: 33
The following statement works expect it's updating all of the occurrences which I understand. I only want to update the first occurrence. I tried using ROW_NUMBER() but can't seem to get a statement working that updates first occurrence based on a condition.
$sql = "UPDATE teams SET teamName = ?, userId = ? WHERE leagueId = ? AND userId = ?;";
Upvotes: 1
Views: 378
Reputation: 1424
You can use the following query for this purpose.
$sql = "UPDATE teams SET teamName = ?, userId = ? WHERE leagueId = ? AND userId = ? ORDER BY teamId ASC LIMIT 1;";
It will limit the result to only the first one with respect to ascending order of teamId column.
Upvotes: 1