TRENDING TOPICS

×

SQL Inner Join

SQL INNER JOIN query used to SELECT all rows from both participating tables as long as there is a match between the columns, and then SQL INNER JOIN will create the result-set by combining all rows from both the tables where the condition satisfied.

INNER JOIN Syntax

SELECT column_name(s)
FROM table_1
INNER JOIN table_2
ON table_1.column_name = table_2.column_name;
  • The SQL INNER JOIN query compares each row of table_1 with the table_2 to find all pairs of row which satisfy the JOIN predicate.
  • The INNER JOIN query will get only those records which are common to the both table_1 and table_2.

JOIN Syntax

SELECT *
FROM table_1
INNER JOIN table_2
ON table_1.column_name = table_2.column_name;

Example With Two Tables

Customers Table

Simple Customers record table & the name of the table is CUSTOMERS. The Column(s) name of the table like [ID, NAME, EMAIL, ADDRESS, and SALARY]:

ID NAME EMAIL ADDRESS SALARY
1 Mark JK mark@gmail.com Mumbai 5000
2 Nitika nitika@gmail.com Delhi 6700
3 Suneel Kumar kumars@gmail.com Pune 9400
4 Jenifer jenifer@gmail.com Indore 3400
5 McKinley mckinley@gmail.com UK 7200
6 Deepika deepika@gmail.com Nashik 3600

Orders Table

This is a sample ORDER table; The columns of the table are [OID, DATE, CUSTOMER_ID, and AMOUNT]:

OID DATE CUSTOMER_ID AMOUNT
210 12/01/2019 2 4000
209 11/22/2019 4 2000
211 12/10/2019 1 1000
212 12/17/2019 6 3000

Mapping Image Of INNER JOIN

JOIN Both Table Using INNER JOIN

SELECT ID, NAME, DATE, AMOUNT, EMAIL
FROM CUSTOMERS
INNER JOIN ORDERS
ON CUSTOMERS.ID = ORDERS.CUSTOMER_ID;

Result Look Like

ID NAME DATE AMOUNT EMAIL
2 Nitika 12/01/2019 4000 nitika@gmail.com
4 Jenifer 11/22/2019 2000 jenifer@gmail.com
1 Mark JK 12/10/2019 1000 mark@gmail.com
6 Deepika 12/17/2019 3000 deepika@gmail.com

© 2021 GDATAMART.COM (All Rights Reserved)