Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Multiple Left Joins on 2 tables

Author  Topic 

simflex
Constraint Violating Yak Guru

327 Posts

Posted - 2009-05-13 : 20:24:37
Greetings SQL Gurus,

I have 2 tables, tableA and tableB

When I run a query that says, Select name1, name2, name3 from
from tableA where ID = parambId and type IN ('G','M')

I get 1 result. This is correct.

when I run tableB, select address, city, state from tableB where ID = paramId and otherId = 1

It returns 4 records which is correct.

The problem is that I want to join the 2 queries using left outer join so I can return everything from tableB and whatever matched from tableA.

Any ideas how to get this to work?

Thanks in advance.

vijayisonly
Master Smack Fu Yak Hacker

1836 Posts

Posted - 2009-05-13 : 20:48:04
Maybe this?

Select A.name1, A.name2, A.name3 ,B.address, B.city, B.state
from tableB B left join tableA A
on B.ID = A.ID
where B.otherId = 1
and A.type IN ('G','M')
Go to Top of Page

simflex
Constraint Violating Yak Guru

327 Posts

Posted - 2009-05-13 : 21:24:47
Thank you very much vijayisonly.

That worked real good.

Thanks a lot
Go to Top of Page
   

- Advertisement -