Page 1 of 1

INSERT INTO with JOIN Query Question [Solved]

Posted: Sun Sep 26, 2010 2:57 pm
by christh
Hi

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'
	") ;

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

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'
	") ;
Could somebody advise on the correct syntax for using INSERT INTO with a JOIN query?

Again, many thanks in advance.

Chris

Re: INSERT INTO with JOIN Query Question

Posted: Sun Sep 26, 2010 3:21 pm
by buckit
What is the error you are getting?

Re: INSERT INTO with JOIN Query Question

Posted: Sun Sep 26, 2010 3:29 pm
by christh
Invalid argument - mysql_fetch_array(): supplied argument is not a valid

Thanks

Re: INSERT INTO with JOIN Query Question

Posted: Sun Sep 26, 2010 3:32 pm
by buckit
google your question: using INSERT INTO with a JOIN query

comes up with a lot of results that may help you out.

Re: INSERT INTO with JOIN Query Question

Posted: Sun Sep 26, 2010 3:38 pm
by christh
Thanks buckit -

Not sure what I have just done that is any different to what I was doing before but it's working now - maybe I've just be looking at it for too long.

Insert line now reads - sure I tried that earlier...

Code: Select all

("INSERT INTO cs  (cid, date, name, location, city, status, discipline, CV, interested)
Thanks anyway.

Chris