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

Query Question

Status
Not open for further replies.

james0816

Programmer
Jan 9, 2003
295
US
two tables...TableA and TableB. Both tables have the following common field names but not data: Field1, Name, Location

Field1 is unique so that there will be no duplicate values between tables.

I want to seach both tables for a value in Field1 and retrieve the Name and Location fields only from which ever table it is found in.

What is the easiest way to code this? So we'll say I am looking for a value of '0010398' that could be in either table.

Did that make sense?
 
Hi

Code:
[b]select[/b] field1,name,location [b]from[/b] table1 [b]where[/b] field1=[i]'0010398'[/i]
[b]union all[/b]
[b]select[/b] field1,name,location [b]from[/b] table2 [b]where[/b] field1=[i]'0010398'[/i]

[gray]-- or[/gray]

[b]select[/b] * [b]from[/b] (
  [b]select[/b] field1,name,location [b]from[/b] table1
  [b]union all[/b]
  [b]select[/b] field1,name,location [b]from[/b] table2 
) foo [b]where[/b] field1=[i]'0010398'[/i]

Feherke.
 
thx..that's the way i had it. just thought there might be a better way.
 
you should have posted your join in your original question then. It would save someone typing up all the information you already had now wouldn't it?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top