MySQL Forums
Forum List  »  Newbie

Re: Looking up a value in a 'subtable' and inserting it if it doesn't exist
Posted by: Dave Kennard
Date: May 02, 2009 04:07AM

Thanks for those links, so I guess
INSERT INTO cameras SET camera = 'my camera' ON DUPLICATE KEY UPDATE id=LAST_INSERT_ID(id);
SET @camera = LAST_INSERT_ID(); etc.
INSERT INTO imageData SET camera = @camera, etc.

Is faster than:
INSERT IGNORE INTO cameras SET camera = 'my camera'; etc.
INSERT INTO imageData SET camera = (SELECT id FROM cameras WHERE camera = 'mycamera'), etc.

In those posts you linked to, the examples were using the API to get the LAST_INSERT_ID(). I presume it's just as fast (or faster) to set a variable in mysql to the LAST_INSERT_ID() than it is to do this in PHP (or whatever language)?

Thanks

Dave

Options: ReplyQuote




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.