INSERT INTO with JOIN Query Question [Solved]

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
christh
Forum Commoner
Posts: 25
Joined: Sat Jan 16, 2010 5:27 am

INSERT INTO with JOIN Query Question [Solved]

Post 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
Last edited by christh on Sun Sep 26, 2010 3:39 pm, edited 1 time in total.
buckit
Forum Contributor
Posts: 169
Joined: Fri Jan 01, 2010 10:21 am

Re: INSERT INTO with JOIN Query Question

Post by buckit »

What is the error you are getting?
christh
Forum Commoner
Posts: 25
Joined: Sat Jan 16, 2010 5:27 am

Re: INSERT INTO with JOIN Query Question

Post by christh »

Invalid argument - mysql_fetch_array(): supplied argument is not a valid

Thanks
buckit
Forum Contributor
Posts: 169
Joined: Fri Jan 01, 2010 10:21 am

Re: INSERT INTO with JOIN Query Question

Post by buckit »

google your question: using INSERT INTO with a JOIN query

comes up with a lot of results that may help you out.
christh
Forum Commoner
Posts: 25
Joined: Sat Jan 16, 2010 5:27 am

Re: INSERT INTO with JOIN Query Question

Post 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
Post Reply