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)
 join question

Author  Topic 

helixpoint
Constraint Violating Yak Guru

291 Posts

Posted - 2009-08-26 : 12:06:41
I have 2 tables..Table 1 School...Table 2 SchoolUsers. I want to join the 2 tables and bring back all schools. In the SchoolUsers table there is a bit field that is "SchoolSiteMainContact"... Some schools may or may not have a main contact or maybe they don't have any users, but I still want to bring back all the schools. Here is my shot at it. It does not work

SELECT SchoolSite.ID, SchoolSite.School, SchoolSiteUser.SchoolSiteEmail
FROM SchoolSite LEFT OUTER JOIN
SchoolSiteUser ON SchoolSite.ID = SchoolSiteUser.SchoolSiteID
WHERE (SchoolSiteUser.SchoolSiteMainContact = 1)

Dave
Helixpoint Web Development
http://www.helixpoint.com

ramireddy
Starting Member

4 Posts

Posted - 2009-08-26 : 12:31:14
change your where clause to

where SchoolSiteUser.SchoolSiteMainContact = 1 or SchoolSiteUser.SchoolSiteMainContact is null
Go to Top of Page

Ifor
Aged Yak Warrior

700 Posts

Posted - 2009-08-26 : 12:33:18
You need to understand this and the related links:

http://blog.sqlauthority.com/2009/04/06/sql-server-logical-query-processing-phases-order-of-statement-execution/
Go to Top of Page
   

- Advertisement -