MySQL Forums
Forum List  »  General

How to get ID from select/update/insert trio?
Posted by: Josh Higham
Date: October 28, 2004 11:04PM

I have a table for users (id, name, password, logins) with id being autoincrement. When users log in, I'd like to be able to send a single query and retrieve the id, either inserting a record if it doesn't exist, updating logins if it exists, or in some cases (for similar tables) just select(id) if it exists, or insert (and get the auto_increment id) if it doesn't exist.

The INSERT ... ON DUPLICATE syntax almost does what I want, but doesn't appear to return the id. Is there a way to narrow this down to a single query, or am I stuck doing a select, and then insert/update?

Version 4.1.7

Thanks.

Options: ReplyQuote


Subject
Written By
Posted
How to get ID from select/update/insert trio?
October 28, 2004 11:04PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.