Question
Multiple MySQL Insert statement for relational tables
Running on PHP but anyone with good knowledge of SQL/MySQL
can help.
I have two tables - Contacts and Contact Notes. Contacts has a Unique ID, as does Contact Notes but Contact Notes also has a column to link each record to a record in the Contacts Table - all fairly simple relational database stuff so far.
I have just completed a mailmerge (mailshot) to 300 records that have been marked in the database and I would like to be able to add a note to every individual record identifying that this has been done. Obviously doing this for each one would be very time consuming.
The statement would be something like this:
INSERT INTO CONTNOTES (NOTECONTACTID,CREATEDATE,NOTE) VALUES ('????????','2007-01-11','Mailshot sent')
INNER JOIN CONTNOTES ON CONTACTS.CONTACTID = CONTNOTES.NOTESCONTACTID
WHERE CONTACTS.MERGECODE = 'Marked for mailshot'
Firstly, do I need to the innerjoin section and secondly, what the hell do I put in the ?????? part?
The Unique ID for each record in both tables is an autoincrement so I don't need to worry about that. It's the link ID insert value I can't get my head round.
Is this even possible?
I have two tables - Contacts and Contact Notes. Contacts has a Unique ID, as does Contact Notes but Contact Notes also has a column to link each record to a record in the Contacts Table - all fairly simple relational database stuff so far.
I have just completed a mailmerge (mailshot) to 300 records that have been marked in the database and I would like to be able to add a note to every individual record identifying that this has been done. Obviously doing this for each one would be very time consuming.
The statement would be something like this:
INSERT INTO CONTNOTES (NOTECONTACTID,CREATEDATE,NOTE) VALUES ('????????','2007-01-11','Mailshot sent')
INNER JOIN CONTNOTES ON CONTACTS.CONTACTID = CONTNOTES.NOTESCONTACTID
WHERE CONTACTS.MERGECODE = 'Marked for mailshot'
Firstly, do I need to the innerjoin section and secondly, what the hell do I put in the ?????? part?
The Unique ID for each record in both tables is an autoincrement so I don't need to worry about that. It's the link ID insert value I can't get my head round.
Is this even possible?