# MS SQL Select Data From Multiple Tables



## NestleCrunch

Greets! Before I get started, I just want to make it clear that I did search for the answer to this question on my own. I could not understand or use the tutorials I did happen to find. I think I just need some basic clarification.

I am running Microsoft SQL Server 2008 R2. I have two tables I need to select data from and display together. One table is called "Courses". The other is called "Sessions".

There is only one common field these tables share, the "Course ID".

I would like to display all the data from both tables in a format that combines the two tables based on the "Course ID". There may be multiple rows showing the same "Course ID", but different "Session IDs" and "Locations".

Could someone please help me understand the syntax of the SELECT command I need?

Much thanks!


----------



## Crockeo

This is actually quite funny, I've been trying to figure this out for a while and I just did.

If I'm not mistaken it's something like:


Code:


SELECT C.*, S.*
FROM Courses C, Sessions S
WHERE C.[Course ID] = S.[Course ID]

Or for an actual join:


Code:


SELECT C.*, S.*
FROM Courses C JOIN Sessions S
ON C.[Course ID] = S.[Couse ID]

They're both equally as small (in lines) so it's really your choice.


----------



## NestleCrunch

Hey! Thanks for the reply! It took me a while to get my head around this. I hope other people can stumble across this and find it useful too!

My app is now working the way I needed it to. I also found this page to be useful in understanding the join command:

SQL Server Basics: Select from multiple tables using INNER JOIN


----------

