Page 1 of 1

Crazy MAD Query I Love IT!!!

Posted: Thu Mar 23, 2006 9:20 pm
by Benjamin
I have spent a week writing this incredibly long query which is dynamically created by over 1000 lines of PHP code and crosses 6 tables (so far - 6 joins) and over 80 fields and it includes math equations in it that I don't even quite understand. I need to take it to the next level now.

Is there a way for me to add to it, so that it automatically inserts all the retrieved records into a 7th table? I'm not sure if this is possible or not but if it is I am thinking that having the query do it would be more efficient than writing PHP to insert the results.

If it is possible can you please write an example of how it can be done or provide me with a link or search phrase to learn how to do it?

...

Posted: Thu Mar 23, 2006 9:43 pm
by crackedPavement
I think the question that you should be asking is why.

Posted: Thu Mar 23, 2006 9:45 pm
by Todd_Z

Code: Select all

CREATE TABLE table ( SELECT .... );
This will create a new table with your retrieved fields.

Posted: Thu Mar 23, 2006 11:42 pm
by Benjamin
I need to insert the data into an existing table.

Posted: Thu Mar 23, 2006 11:59 pm
by feyd
SELECT INTO

Posted: Fri Mar 24, 2006 12:27 am
by Benjamin
cool thank you are tha man!