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!

Union query problem

Status
Not open for further replies.

shteev

Programmer
Jul 15, 2003
42
0
0
Hi, I want to make a union query which adds 2 tables together; but I want it to contain a field which is in one table, but not the other. For entries in the second table, I want the union query to contain a NULL. So, something like this:

SELECT [field1], [field2], [field3]
FROM [table1]
UNION
SELECT [field1], [field2], [just have a load of NULL fields]
FROM [table2]

Is this possible?
 
Hi!

Have you tried something like this:

[tt]SELECT [field1], [field2], [field3]
FROM [table1]
UNION
SELECT [field1], [field2], null as myfield
FROM [table2][/tt]

or

[tt]SELECT [field1], [field2], [field3]
FROM [table1]
UNION
SELECT [field1], [field2], "" as myfield
FROM [table2][/tt]

Roy-Vidar
 
This works great! I had tried [null] which didn't work for reasons which appear all to obvious to me now...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top