INSERT INTO with JOIN Query Question [Solved]
Posted: Sun Sep 26, 2010 2:57 pm
Hi
The query below using INNER JOIN works and delivers the results I want..
I would like to insert the results into a table however when I use INSERT INTO in various ways I get an error - obviously my use of INSERT INTO is incorrect in this instance
Could somebody advise on the correct syntax for using INSERT INTO with a JOIN query?
Again, many thanks in advance.
Chris
The query below using INNER JOIN works and delivers the results I want..
Code: Select all
$result = mysql_query
("SELECT cm.id, cm.date, cm.name, cm.location, cm.city, cm.status, cm.discipline, cm.CV, cm.interested
FROM cm
INNER JOIN app
ON cm.id = app.ap_id
INNER JOIN joblist
ON joblist.id = app.apjob_id
WHERE joblist.location like '$loc' AND cm.location NOT like '$loc'
") ;
Code: Select all
$result = mysql_query
("INSERT INTO cs (cs.cid, cs.date, cs.name, cs.location, cs.city, cs.status, cs.discipline,cs.CV, cs.interested)
SELECT cm.id, cm.date, cm.name, cm.location, cm.city, cm.status, cm.discipline, cm.CV, cm.interested
FROM cm
INNER JOIN app
ON cm.id = app.ap_id
INNER JOIN joblist
ON joblist.id = app.apjob_id
WHERE joblist.location like '$loc' AND cm.location NOT like '$loc'
") ;
Again, many thanks in advance.
Chris