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

Join three tables, getting the rows with at least one match

Status
Not open for further replies.

Smulan

Programmer
Apr 11, 2002
5
SE
Hi I want to join three tables, Lets say A, B and C. I want all data from the A table that have at least one row matching in B or C. That Is I dont want the rows from A that do not have an match in eiter B or C, but all the other.

Now the Query looks a bit like this. Which gives me the wrong result

SELECT A.* from A
INNER JOIN B
ON A.Col1 = B.Col1
INNER JOIN C
ON A.Col1 = C.Col1


if the data in the tables looks like this

A.Col1 B.Col1 C.Col1
Bryan Bryan Adam
Ann Sam
David
Sam

I want these rows from table A to be returned:
Bryan
Sam

Thanks for your help.
/Sandra
 
I think i solved the problem :)

select distinct A.* from A
inner join B
ON A.Col1 = B.Col1
union
select distinct A.* from A
inner join C
ON A.Col1 = C.Col1


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top