MySQL Forums :: Newbie :: How do I combine 3 queries into one


Advanced Search

How do I combine 3 queries into one
Posted by: Neil Jensen ()
Date: April 12, 2009 07:37PM

I have three insert queries created:

$result = mysql_query("INSERT INTO item_cat_associations (item_id) SELECT stuff.item_id FROM stuff WHERE stuff.item_id = LAST_INSERT_ID()",$connect);

$result=mysql_query("INSERT INTO item_cat_associations(cat_id) VALUES ('$HTTP_POST_VARS[cat]')", $connect);

$result=mysql_query("INSERT INTO item_cat_associations(sub_id) SELECT subcategory.sub_id FROM subcategory WHERE subcategory.subcategory=('$HTTP_POST_VARS[subcat]')",$connect);

My problem is that , I think, because these are 3 queries, my data into my item_cat_associations table appears three times, so that I have 3 primary key ids for one result.

Can I combine these three queries into one so that I only get one result id?

Options: ReplyQuote


Subject Written By Posted
How do I combine 3 queries into one Neil Jensen 04/12/2009 07:37PM
Re: How do I combine 3 queries into one Peter Brawley 04/12/2009 08:21PM
Re: How do I combine 3 queries into one Neil Jensen 04/12/2009 09:01PM
Re: How do I combine 3 queries into one Neil Jensen 04/12/2009 09:51PM
Re: How do I combine 3 queries into one Rick James 04/12/2009 11:49PM
Re: How do I combine 3 queries into one Neil Jensen 04/13/2009 12:12PM
Re: How do I combine 3 queries into one Rick James 04/13/2009 07:12PM
Re: How do I combine 3 queries into one Neil Jensen 04/13/2009 07:50PM
Re: How do I combine 3 queries into one Rick James 04/13/2009 10:26PM
Re: How do I combine 3 queries into one Neil Jensen 04/14/2009 02:03AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.