UNION Query

Gannet

Registered User.
Local time
Today, 18:47
Joined
Sep 21, 2006
Messages
55
I have two tables with data and I want to join the data together for a report.

Example:

SELECT tbl1.a tbl1.b tbl1.c tbl1.d
FROM tbl1
UNION SELECT tbl2.a tbl2.b tbl2.c
FROM tbl2;

Currently I can't join them b/c the column counts aren't the same.
If table1 has more columns than table2 can I join them by indicating some kind of phantom column 'd' for table2 to be joined to column 'd' of table1?
 
Sure:

SELECT tbl1.a, tbl1.b, tbl1.c, tbl1.d
FROM tbl1
UNION
SELECT tbl2.a, tbl2.b, tbl2.c, "None" As d
FROM tbl2;
 
Works

Worked great. I changed "None" to "" but works now. Thanks pbaldy!
 
No problemo. It can be anything really; I make it a zero when the field in the other table is numeric, just to keep them consistent.
 

Users who are viewing this thread

Back
Top Bottom