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
 General SQL Server Forums
 New to SQL Server Programming
 Need help constructing MS SQL statement

Author  Topic 

mussy
Starting Member

2 Posts

Posted - 2011-10-10 : 07:06:45
Hi all, new here so go easy!

I'm trying to construct a SQL SELECT statement using data from 3 tables, but I'm stumped as to the syntax.

Basically, I have a table of meeting information: tbl_meetings. Within each record on that table, there are two references to ID numbers for each meeting's type, and the category of meeting. These are called categoryID and meetingTypeID

These reference two additional table, tbl_Categories and tbl_MeetingType in order to retrieve the fields categoryName and typeName.

Now, I had all this working when there was only a single JOIN, as only the category information had to be returned, but I now need to return the new info for meetingType too, and it's adding this additional JOIN that's got me stumped.

My original working SQL is:

SELECT m.meetingID, m.categoryID, m.meetingName, m.meetingDate, m.meetingTime, c.categoryName
FROM tbl_Categories AS c RIGHT OUTER JOIN tbl_Meetings AS m ON c.catID = m.categoryID

So now I need to add in the bit to retrieve the Meeting Type, in the same way I'm getting the Category Name at the moment.

I tried:

SELECT m.meetingID, m.categoryID, m.meetingTypeID, m.meetingName, m.meetingDate, m.meetingTime, c.categoryName, t.typeName
FROM tbl_Categories AS c, tbl_MeetingType as t RIGHT OUTER JOIN tbl_Meetings AS m ON c.catID = m.categoryID, t.typeID = m.meetingTypeID

But needless to say, this is generating errors. The bold parts are my bogus additions.

Anybody smart enough to clear this up?!

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-10-10 : 07:09:43
[code]SELECT m.meetingID, m.categoryID, m.meetingTypeID, m.meetingName, m.meetingDate, m.meetingTime, c.categoryName, t.typeName
FROM tbl_Meetings AS m
INNER JOIN tbl_MeetingType as t
ON t.typeID = m.meetingTypeID
LEFT JOIN tbl_Categories AS c
ON c.catID = m.categoryID
[/code]

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

mussy
Starting Member

2 Posts

Posted - 2011-10-10 : 07:22:06
visakh16 - you are a genius.

Thank you so much!
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-10-10 : 07:52:13
np
welcome

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -