Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
06-26-2011, 09:47 PM #1
- Join Date
- Dec 2008
- Thanked 0 Times in 0 Posts
php/sql handling of duplicate records
I have a website that accepts account signups. I insert filler records that some users can "claim", meaning they will see their account listed on the site and want to update/use the profile.
So, if on signup I want to check to see if there's an account with matching fields (ie name and employer), would that require a stored procedure, cursor and / or something similar?
06-26-2011, 10:34 PM #2
You could do it with a stored procedure, but you don't have to.
You could just do it with an ad hoc query.
Just do a SELECT in the table to see if there is a match on the fields you are interested in.
If not match, then use an INSERT.
If there is a match, do an UPDATE instead.
You can *ALSO* always do an INSERT and then add an ON DUPLICATE clause to the INSERT, but (a) that requires that the fields in question be made into a composite index and (b) the query is more complex. Unless you will be inserting/updating thousands of records per hour, I'd just go with the SELECT followed by either INSERT or UPDATE.