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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need Little Help with Union Query 1

Status
Not open for further replies.

houstonbill

Technical User
Nov 6, 2006
92
I have 2 tables I am trying to joing. tblOpenCases has 32 columns and tblClosedCases has 30 columns, which match 30 of the 32 columns in OpenCases. Without having to spell out all the columns, I first tried the below SQL:

SELECT * FROM tblClosedCases
UNION SELECT * FROM tblOpenCases;

With this I get an error indicating the number of columns do not match. I tried differnt variations but none seem to work. Assistance on getting this to work in the simplest format would be much appreciated.
 
if the additional two columns are either at the beginning or end of the table, then you can do this --

SELECT * FROM tblOpenCases
UNION ALL
SELECT null, null, * FROM tblClosedCases

or this --

SELECT * FROM tblOpenCases
UNION ALL
SELECT *, null, null FROM tblClosedCases

otherwise, you will need to list the columns you want, and put NULLs in the appropriate places



r937.com | rudy.ca
 
Your first choice worked perfectly, and so simple. Duh, I had not thought of using Null.
Thanks so much for your help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top