Inner Join will return common records appearing in tables. INNER JOIN is also known as JOIN.
Inner Join requires two tables to be joined by linking with ON condition. We can add more condition by using WHERE clause. Area as per venn diagram B
These two table we will use for our examples
Table one ( t1 )
Table two ( t2)
id
name1
1
one1
2
two1
3
three1
id
name2
1
one2
2
two2
4
four2
Joining tables Using SQL LEFT Join, RIGHT Join and Inner Join
QUERY using Inner Join
The common records between two tables will be returned.
SELECT * from t1 INNER JOIN t2 on t1.id=t2.id
id
name1
id
name2
1
one1
1
one2
2
two1
2
two2
Example : products & sales table
Area
Description
B & C
There are matching values in both tables for p_id column
A
These products ( table 1 ) have no matching p_id in sales ( table 2 )
D
These sales (table 2 ) have no matching p_id in products ( table 1 )
Type of join and expected output
Type
Table 1
Table 2
Details
LEFT
A + B
C
All from Left ( Table 1 ) and matching from right (Table 2 )
RIGHT
B
C + D
All from Right ( Table 2 ) and matching from left (Table 1 )
INNER
B
C
Matching from Left ( Table 1 ) and right (Table 2 )
CROSS
A + B
C + D
All from Left ( Table 1 ) join to all from right (Table 2 )
INNER JOIN will return rows where join column value is available in both tables. Here the area B of products_v2 table and area C of sales_v2 table will be returned.
SELECT * from products_v2 a INNER JOIN sales_v2 b on a.p_id=b.p_id