The stored procedure is goin to take in a firstName, lastName, currentPostalCode and newPostalCode as arguements. I want to update the postalCode column only if there is one person with the given firstName, lastName and currentPostalCode.
How is this done? Do you use sub queries or the MySQL IF() or something else?
Thanks.
You don’t need any fancy conditional logic to perform this action, just a regular
UPDATEstatement with aWHEREclause will do it. If no rows is matched by theWHEREclause, no update takes place.As a stored procedure:
Addendum: If you really only want to do this if there is exactly one match…
To update only in the event of exactly one matching row (not 2 or more), you can still use a plain update statement, with an additional subquery in the
WHEREclauseAddendum 2 To exit with error if there is not exactly one match: