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 2000 Forums
 Transact-SQL (2000)
 Join question

Author  Topic 

obewankanoochie
Starting Member

24 Posts

Posted - 2005-10-31 : 19:34:57
Okay, I've got 3 tables. Subjects are the main table, and comments relate to subjects. However, some subjects won't have any comments to them. I'm stumped on how to get all the subjects even if they have comments. If they do have comments, I want those returned as well. Any help is greatly appreciated. Thanks.


tblSubjects
==========
Id
groupId
memberId
Title
SubjectData


tblComments
===========
commentId
subjectId
memberId
CommentData


member
===========
memberId
memberPhotoUrl


SELECT s.Id, s.memberId, s.Title, s.SubjectData, m.memberPhotoUrl, c.memberId, c.CommentData
FROM tblSubjects s, tblComments c, member m
WHERE s.groupId = #groupId#
AND s.SubjectId = #Id#
AND c.SubjectId = #Id#
AND s.memberId = m.member_id
AND c.memberId = m.member_id
ORDER BY s.Id ASC

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2005-10-31 : 19:40:54
read about joins in Books online = sql server help.
USE them!!
use left join for your problem.

Go with the flow & have fun! Else fight the flow
Go to Top of Page
   

- Advertisement -