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.
| 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 meetingTypeIDThese 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.categoryNameFROM tbl_Categories AS c RIGHT OUTER JOIN tbl_Meetings AS m ON c.catID = m.categoryIDSo 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.typeNameFROM tbl_Categories AS c, tbl_MeetingType as t RIGHT OUTER JOIN tbl_Meetings AS m ON c.catID = m.categoryID, t.typeID = m.meetingTypeIDBut 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.typeNameFROM tbl_Meetings AS m INNER JOIN tbl_MeetingType as tON t.typeID = m.meetingTypeIDLEFT JOIN tbl_Categories AS cON c.catID = m.categoryID[/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
mussy
Starting Member
2 Posts |
Posted - 2011-10-10 : 07:22:06
|
| visakh16 - you are a genius.Thank you so much! |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-10-10 : 07:52:13
|
npwelcome ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|
|
|
|