Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Dec 2008
    Posts
    18
    Thanks
    3
    Thanked 0 Times in 0 Posts

    php/sql handling of duplicate records

    Hello:

    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?

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,620
    Thanks
    78
    Thanked 4,388 Times in 4,353 Posts
    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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •