0% found this document useful (0 votes)
145 views

SQL Server Interview Questions - Inner Join With An Example

This document discusses inner joins in SQL Server with an example. It describes how an inner join returns rows where the foreign key value in one table matches the primary key in another table. The example shows creating two tables, Company and Candidate, with CompanyId as a foreign key in Candidate. An inner join query on these tables returns only rows from Candidate where CompanyId is not null, matching the primary key in Company.

Uploaded by

parashuram n
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
145 views

SQL Server Interview Questions - Inner Join With An Example

This document discusses inner joins in SQL Server with an example. It describes how an inner join returns rows where the foreign key value in one table matches the primary key in another table. The example shows creating two tables, Company and Candidate, with CompanyId as a foreign key in Candidate. An inner join query on these tables returns only rows from Candidate where CompanyId is not null, matching the primary key in Company.

Uploaded by

parashuram n
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

12/24/2016 SQL Server Interview Questions: Inner Join with an example

0   More    Next Blog» Create Blog   Sign In

SQL Server Interview Questions
C#
Boo MV ASP. C SQL W Written HR Subsc SQL Buy
Program 0
ks C NET # Server CF Test Round ribe Tutorial DVD
s

If you like this website, please share


this site using g+1 button Inner Join with an example
Recommend this on Google
Get Android certified

Best software training institute in bangalore for SAP ABAP,
SAP BI, .Net, Informatica, Software Testing, Siebel CRM
I am Venkat and this is my website. I did training in Pragim
Technologies and got job in Dell in less than a week. PRAGIM is the
best S/W training institute in Bangalore.
Click here for Hyderabad Center Website
For further details please call 09900113931.

Royal Challenge Sports Drin


Please read, Basic SQL Server Interview Questions on Joins article before
reading this article.

Inner Join and left join are the most commonly used joins in real time projects.
We will talk about left join in a later article. Now, let us understand Inner join
with an example.

Create 2 tables Company and Candidate. Use the script below to create these
tables and populate them. CompanyId column in Candidate Table is a foreign key
referencing CompanyId in Company Table.

CREATE TABLE Company
(
    CompanyId TinyInt Identity Primary Key,
CLICK TO KNOW MORE
    CompanyName Nvarchar(50) NULL
)
GO
SAP BI Training in Bangalore
Best SAP BI Training institute in Bangalore, INSERT Company VALUES('DELL')
Marathahalli. Real time project based training INSERT Company VALUES('HP')
provided by working software professionals INSERT Company VALUES('IBM')
having more than 10 years of experience. INSERT Company VALUES('Microsoft')
Informatica Training in Bangalore GO
Informatica training in bangalore delivered by
a real time software expert having 10 years CREATE TABLE Candidate
of experience.  (
Siebel CRM Training in Bangalore     CandidateId tinyint identity primary key,
Best software training institute for Siebel CRM     FullName nvarchar(50) NULL,
training in Marathahalli, Bangalore.      CompanyId tinyint REFERENCES Company(CompanyId)
Software testing training institute in )
bangalore GO

http://venkatsqlinterview.blogspot.in/2011/05/inner­join­with­example.html 1/3
12/24/2016 SQL Server Interview Questions: Inner Join with an example

Software testing training on real time projects INSERT Candidate VALUES('Ron',1)
and placements.  INSERT Candidate VALUES('Pete',2)
MSBI Training Institute in Bangalore INSERT Candidate VALUES('Steve',3)
Best MSBI Training in Bangalore by an INSERT Candidate VALUES('Steve',NULL)
expert. MSBI training on real time projects INSERT Candidate VALUES('Ravi',1)
and placements.  INSERT Candidate VALUES('Raj',3)
Basic SQL Server Interview Questions INSERT Candidate VALUES('Kiran',NULL)
GO
SQL Server Interview Questions on
Temporary Tables
Royal Challenge Sports Drin...
SQL Server Interview Questions on
Indexes ‐ Part 1

SQL Server Interview Questions on


Indexes ‐ Part 2

What is the difference between


Having and Where clause

What is the difference between a


Temporary Table and a Table Variable

What is the use of COALESCE in SQL


Server

SQL Server Interview Questions on


triggers If you want to select all the rows from the LEFT table(In our example Candidate
Table) that have a non null foreign key value(CompanyId in Candidate Table is
Difference between User Defined the foreign key) then we use INNER JOIN. A query involving an INNER JOIN for
Function and Stored Procedure the Candidate and Company Table is shown below. 

SQL Server Interview Questions on SELECT Cand.CandidateId, Cand.FullName, Cand.CompanyId,


Views ‐ Part 1 Comp.CompanyId, Comp.CompanyName
FROM Candidate Cand
SQL Server Interview Questions on INNER JOIN Company Comp
Views ‐ Part 2 ON Cand.CompanyId = Comp.CompanyId

Basic SQL Server Interview Questions If we run the above query the output will be as shown in the image below. If you


on Joins look at the out put, we only got 5 rows. We did not get the 2 rows which has
NULL value in the CompanyId column. So an INNER JOIN would get all the rows
Explain Inner Join with an example from the LEFT Table that has non null foreign key value.

Explain Left Outer Join with an


example

Explain Right Outer Join with an


example

Explain Full Outer Join with an


example
Inner Join Result
Explain Self Join with an example
Instead of using INNER JOIN keyword we can just use JOIN keyword as shown
What is the difference between Index below. JOIN or INNER JOIN means the same.
Scan and Index Seek
SELECT Cand.CandidateId, Cand.FullName, Cand.CompanyId,
Write a SQL Query to delete from a Comp.CompanyId, Comp.CompanyName
table that is involved in a SQL join FROM Candidate Cand
JOIN Company Comp
What are the advantages of using ON Cand.CompanyId = Comp.CompanyId
stored procedures
If you can think of any other sql server interview questions please post
What are the different ways to them as comments, so they will be useful to other users like you. This will
replace NULL values in SQL Server be a great help from your side to improve this site.
http://venkatsqlinterview.blogspot.in/2011/05/inner­join­with­example.html 2/3
12/24/2016 SQL Server Interview Questions: Inner Join with an example

Recommend this on Google


SQL Server interview questions on
string manipulation functions

Write a Stored Procedure that takes 1 comment:


column name as a parameter and
returns the result sorted by the
column that is passed [email protected] August 7, 2014 at 6:51 AM
What is deferred name resolution in venkat can u show me one example for fetching the emp details
SQL Server? n dept details frm two tables using join with emp joining date
with time?
Reply

Enter your comment...

Comment as:  Select profile...

Publish
  Preview

If you are aware of any other sql server questions asked in an


interview, please post them below. If you find anything missing or
wrong, please feel free to correct by submitting the form below.

Newer Post Home Older Post

Subscribe to: Post Comments (Atom)

 
Disclaimer ­ Terms of use ­ Contact Us

http://venkatsqlinterview.blogspot.in/2011/05/inner­join­with­example.html 3/3

You might also like