SQL Server - INNER JOIN
What is INNER JOIN in SQL Server ?
In relational database we store data in multiple table with some relationship between them.
To retrieve the common (union) data from multiple table we use INNER JOIN in SQL Server. We can use only JOIN instead of INNER JOIN in SQL Server because JOIN default indicate INNER JOIN.
Below image will give you brief idea regarding inner join. We have to tables and it is showing only common data from both tables.
Syntax of JOIN / INNER JOIN
Note : We use the INNER JOIN keyword to join two or more table and ON keyword is use to add condition. We can add multiple condition using AND keyword.
Consider below two result set of tblStudentDetails table and tblStudentMarks table, having student and student marks details.
Select the record from table Student Id, Student Name, Subject and Marks student who having marks.
Note : If you observe above JOIN statement then you can see JOIN result set not show the data of Jyo and Sudarshan because both student not having marks data.
It mean INNER JOIN it return the common data from both table.
Jon on more than two table in SQL server.
Consider below three result set of tblStudentDetails table, tblStudentMarks table and tblStudentContact table.
Select the matching record from table Student Id, Student Name, Subject and Marks student who having marks and also Student Contact.
Note : In above example only one student Yogesh having record in all three table, so only one record show in output of JOIN.
INNER JOIN with where condition.
Consider the below result set and select student whose marks greater than 50 and subject in Math and Science .