SQL -Structured Query Language - SQL Joins - Inner Join Tutorial
Inner Join is used to retrieve the only record, that having matched column value (e.g id) on both tables.
We can perform inner joins in multiple tables.
The syntax for inner joins is-
SELECT column_name1,column_name2,..,column_nameN
FROM
table_1 INNER JOIN table_2
ON
table_1.column_name = table_2.column_name;
For example-
SELECT first_name,email,salary,start_date,end_date
FROM
employees
inner join
job_history
WHERE
employees.employee_id = job_history.employee_id;
Better to use AS (Alias) for the long table name-
SELECT e.first_name,e.email,e.salary,jh.start_date,jh.end_date
FROM
employees as e
inner join
job_history as jh
WHERE
e.employee_id = jh.employee_id;
Here we will get only those records where employee_id will get matched in both employees and job_history table.
Other records that is not matched will not get retrieved.