Jump to content

INSERT with WHERE condition


boneXXX

Recommended Posts

Hi all,

 

I need your advise for inserting data into database.

 

To understand the concept could you just help me on this made up example please :

 

such as there are ID(Primary), firstname, surname columns and I want to insert fistname data first then surname data second in different points.

 

INSERT INTO Member(firstname) VALUES ('Max');

 

INSERT INTO Member(surname) VALUES('Power');

 

The data will be inserted in two different rows. So my question is how can I use the automatically generated ID number to insert this values into the same row in two different points. I don't does make sense or not, it is just a example that I made up. Could you help me on this please? Thank you.

Link to comment
https://forums.phpfreaks.com/topic/128345-insert-with-where-condition/
Share on other sites

Pretty much.  You can get the ID as the row is created as well.  How long after you create the Firstname are you looking to set the Surname?  Same script or different?  If you wait too long and you get more than 1 firstname that is the same, you're looking at some problems you'll have to figure out.

Either

INSERT INTO member (firstname, surname) VALUES ('Max', 'Power')

 

or

INSERT INTO Member(firstname) VALUES ('Max');

UPDATE Member SET surname='Power' WHERE id = LAST_INSERT_ID();

 

Note that LAST_INSERT_ID is only available until the current mysql connection is closed

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.