Forcing left join to only return one row from matching Ids in the right table

Viewed 18033

I have two tables in which I'd like to join, the right table sometimes has more than 1 row for each ID. But I'm not interested to have all the matches, only the first one is enough.

How can I do that?

Example:

Foo:

     Id             FooColumns....
     100             xxxxxxxx
     200             xxxxxxxx
     300             xxxxxxxx
     400             xxxxxxxx

Bar:

     Id             BarColumns....
     100             yyyyyyyy
     100             zzzzzzzz
     200             yyyyyyyy
     200             zzzzzzzz

What I want to have is :

FooBar:

     Id             FooColumns....     BarColumns
     100             xxxxxxxx            yyyyyyyy
     200             xxxxxxxx            yyyyyyyy
     300             xxxxxxxx              nulls
     400             xxxxxxxx              nulls

Query: 
   Select F.*,B.* from Foo f left join Bar b on f.Id=B.Id   ?? 
4 Answers
Related