Jacobvu84 / sql-basic-advance

SQL
0 stars 0 forks source link

Left join and Right join #2

Open Jacobvu84 opened 6 months ago

Jacobvu84 commented 6 months ago

image

select u.unique_id, e.name
from Employees as e
left join EmployeeUNI as u on e.id = u.id

image

Returns all records from the left table (table1), and the matching records from the right table (table2). The result is null records from the right side, if there is no match.

Jacobvu84 commented 6 months ago
select u.unique_id, e.name
from Employees as e
right join EmployeeUNI as u on e.id = u.id

Returns all records from the right table (EmployeeUNI), and the matching records from the left table (Employees). The result is 0 records from the left side, even if there are no matches in the left table.

Jacobvu84 commented 6 months ago
select u.unique_id, e.name
from Employees as e
inner join EmployeeUNI as u on e.id = u.id

Return records that have matching values in both tables