>>> Programming >> MSSQL > How to make a Join, and what type of join should i use? (This page has been seen 470 times)
How to make a Join, and what type of join should i use?
A Join is a command in SQL Server which can Join multiple tables together.
INNER JOIN?.
SELECT * FROM MyTable INNER JOIN MyTable2 ON MyTable.Id = MyTable2.Id
This will return data from both tables. But only if the data exist in both tables that you join together. This means that you cannot do an inner join on a table that doesnt hold the Join value. This will return nothing. If you want to Join something on your primary table but arent sure it exist in the second table use the LEFT JOIN command Like this.
SELECT * FROM MyTable LEFT JOIN MyTable2 ON MyTable.Id = MyTable2.Id
INNER JOIN?.
SELECT * FROM MyTable INNER JOIN MyTable2 ON MyTable.Id = MyTable2.Id
This will return data from both tables. But only if the data exist in both tables that you join together. This means that you cannot do an inner join on a table that doesnt hold the Join value. This will return nothing. If you want to Join something on your primary table but arent sure it exist in the second table use the LEFT JOIN command Like this.
SELECT * FROM MyTable LEFT JOIN MyTable2 ON MyTable.Id = MyTable2.Id
Like
Dislike
Keywords for this article:
SELECT || TSQL || SQL || JOIN
Advertisement by Google
Comment:
Code Language:
Code:
Here you can paste a code example. It will then be processed by SyntaxHighlighter and formatted for easier readability.
Please remember to select the correct Code Language in the select above so the SyntaxHighlighter can highlight the code properly.
Code:
Please enter the code you see above
What is 10 + 9 =