0% found this document useful (0 votes)
7 views14 pages

Data Retrieval - 12

The document explains the concept of INNER JOIN in SQL, which is used to fetch records with matching values from two tables. It highlights the use case for INNER JOIN, provides an example scenario, and discusses its differences from other join types like OUTER JOIN. Additionally, it addresses common questions related to INNER JOIN, such as handling non-matching records and joining on multiple columns.

Uploaded by

satish.gsat
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views14 pages

Data Retrieval - 12

The document explains the concept of INNER JOIN in SQL, which is used to fetch records with matching values from two tables. It highlights the use case for INNER JOIN, provides an example scenario, and discusses its differences from other join types like OUTER JOIN. Additionally, it addresses common questions related to INNER JOIN, such as handling non-matching records and joining on multiple columns.

Uploaded by

satish.gsat
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 14

Part - 12

Data Retrieval
Interview
Q A
..!
es th
ns
wi
tio

in qu
g

ar
Sh ter
oun
C

Krishan kumar
@Krishan kumar
How can you fetch
common records from
two tables?
What is an INNER JOIN?

An INNER JOIN is used in SQL to fetch records


that have matching values in both tables.

It returns only the rows where there is a match


between specified columns.

Why use INNER JOIN for this task?


Use of INNER JOIN

INNER JOIN is ideal for fetching common records


because it only includes rows that satisfy the
matching condition across both tables.

If there's no match, the rows are excluded from


the results.

Can you give an example of using it for better understanding?


Example Scenario:
Suppose we have two tables, TableA and TableB,
which both contain an ID column:
TableA:
ID Name

1 John

2 Alice

3 Bob

TableB:

ID Product

2 Laptop

3 Tablet

What are SQL query for this problem lets see.


SQL Query to Fetch Common
Records:

Result:

ID Name Product

2 Alice Laptop

3 Bob Tablet

Let’s provide us a Summary:


Summary:

INNER JOIN: Returns rows with matching


values in both tables based on the specified
condition.

Use Case: Ideal for identifying overlapping


data, like shared records between different
datasets.

for the jackpot o


ht f th
ig ed
Sw
ipe
r
😉
ay
wanna see some
Counter Questions

umar
krishan k
1. What happens if there are no
matching records?
If there are no matching values, an INNER JOIN
will return an empty result set.

This makes it different from LEFT JOIN or RIGHT


JOIN, which would still include non-matching
rows from one of the tables.

It is useful when you only need rows with exact


matches.
Next Question
2. Can we use multiple columns for
joining?
Yes, you can join tables using multiple columns
by specifying multiple conditions in the ON
clause.

For example,
ON TableA.ID = TableB.ID
AND TableA.Name = TableB.Name.

This helps to ensure more specific matches


between the tables.
ion
st
ue
tQ
x
Ne
3. How is INNER JOIN different from
OUTER JOIN?
An INNER JOIN returns only matching rows,
while an OUTER JOIN (like LEFT JOIN or
RIGHT JOIN) includes all rows from one table
and matching rows from the other.

OUTER JOIN helps in scenarios where you


want to keep all records from one table
regardless of matches.

ion
st
ue
t Q
x
Ne
4. Can we fetch common records
from more than two tables?
Yes, you can use multiple INNER JOIN clauses
to fetch common records from three or more
tables. Just add another INNER JOIN for each
additional table.

This is useful in complex queries where multiple


relationships exist.

re
mo
nts
wa
Ciku
5. What if the column names are
different in both tables?
You can still join the tables by specifying the
correct column names in the ON clause,
like:

ON TableA.ID_A = TableB.ID_B.

Using aliases for table names can also make the


query easier to read and manage.

you completed one interview question


with me,
can you do me a favour
Find This Useful

Time to hit that like button


and give it some love! 🤩

😉
Visit my Linkedin for such amazing Content
krishan kumar

You might also like