Crazy MAD Query I Love IT!!!

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Crazy MAD Query I Love IT!!!

Post 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?
crackedPavement
Forum Newbie
Posts: 11
Joined: Wed Mar 01, 2006 8:18 pm
Location: portland, or

...

Post by crackedPavement »

I think the question that you should be asking is why.
User avatar
Todd_Z
Forum Regular
Posts: 708
Joined: Thu Nov 25, 2004 9:53 pm
Location: U Michigan

Post by Todd_Z »

Code: Select all

CREATE TABLE table ( SELECT .... );
This will create a new table with your retrieved fields.
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

I need to insert the data into an existing table.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

SELECT INTO
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

cool thank you are tha man!
Post Reply