Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Save Query Result as a New Table while using Union All 1

Status
Not open for further replies.

SDB15

Technical User
Apr 9, 2009
21
US
I'm taking data from several tables (unlinked) and using union all to combine it all into one massive table. The query runs perfectly now but I cannot save it to a new table because syntax requires into to be placed after SELECT but before FROM. Is there any way to do this using a stored proceedure or maybe an INSERT command?

Thanks
 
You mean like this?

Code:
SELECT * INTO NewTableName

FROM

(
  SELECT * FROM Table1
  UNION ALL
  SELECT * FROM Table2
) x
 
Wow, that was a lot easier than I thought it would be. Thanks!
What is the purpose of the 'x' at the end? I know it won't work without it but I've never seen that before.
 
Correction - you need a table alias when you're using derived table.
 
The 'x' could be anything. It's just a temporary name for the derived table as they said.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top