Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
2.00/5 (2 votes)
See more:
can u give clear and easy expalnation about INNER JOIN concept with the example of 3 tables
Posted
Comments
Santosh K. Tripathi 10-Mar-15 1:34am    
what you tried?
Sergey Alexandrovich Kryukov 10-Mar-15 1:34am    
More general tip: don't look for easy ways in learning; ultimately it can make your life too hard.
—SA

Probably the simplest possible example is used in this description: http://en.wikipedia.org/wiki/Join_%28SQL%29#Inner_join[^].

(But note my comment to the question.)

—SA
 
Share this answer
 
Read the following link


http://www.w3schools.com/sql/sql_join.asp[^]
 
Share this answer
 
 
Share this answer
 
v2
INNER JOIN is actually an intersection.
It returns Joined Tables which has same field value in both tables.
For Eg:

(Student Table)
Id  Name   
---------------------------
1  AAA    
2  BBB     
3  CCC    

(Age Table)
Id   Age 
------------------
1    28
2    25
3    40
3    55 
4    20


SQL
SELECT * FROM Student A INNER JOIN Age B ON A.Id = B.Id

will return 4 Row, which looks like this...
(Result)
Id  Name   Age 
------------------
1   AAA    28
2   BBB    25
3   CCC    40
3   CCC    55 


It won't result you the fifth row from Age Table, as the Name table doesn't have ID 4.

For the below tables,
(Student Table)
Id  Name
---------------------------
1  AAA
2  BBB
3  CCC

(Age Table)
Id   Age  RegID
------------------
1    28   1001
2    25   1002
3    40   1003
3    55   1004
4    20   1004

(Registration Table)
RegID   FileNumber
------------------
1001    F/02/2005
1002    G/03/2015 


SQL
SELECT * FROM Name A INNER JOIN Age B ON A.Id = B.Id INNER JOIN Registration C ON C.RegID = B.RegID; 

will return these rows

(Result)
Id  Name   Age  RegID   FileNumber
---------------------------------
1   AAA    28   1001    F/02/2005
2   BBB    25   1002    F/03/2015


As there are only 2 rows present in Registration Table.
 
Share this answer
 
As already said an inner join returns rows from two joined tables that have a matching column (or columns). If I understood you correctly, you know the concept for joining two tables but you're struggling with the concept of joining three or more tables.

If that is true, then I believe it would help you to think the joins in smaller steps. Joining three tables can be though in two separate steps.

For example:
SQL
SELECT *
FROM a 
     INNER JOIN b ON a.a = b.a
     INNER JOIN c ON b.b = c.b

The idea you can use is that you first think about the join between a and b. This is executed and you would have a new result set containing all the common rows from both tables.

This defines you a new 'table', an intermediate result set. Now this 'table' (or result set) is then again joined with table c. Now the result is common rows from the intermediate result set and table c.

If you would have more tables you could continue the logic as needed.

To put this in another way. The example in the beginning can be written so that you can actually 'see' the intermediate results. Consider the following
SQL
SELECT *
FROM (SELECT *
      FROM a INNER JOIN b ON a.a = b.a) as intermediate_result
     INNER JOIN c ON intermediate_result.b = c.b

Hope this helps.
 
Share this answer
 
Hi,


Check below...

Inner Join[^]

Also check these...


SQL Joins[^]

Types of Joins in SQL[^]


Hope these will help you.


Cheers
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900