Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL Join Differences

Tags:

sql

join

What's difference between inner join and outer join (left join,right join), and which has the best performance of them?

Thanks!

like image 895
leo Avatar asked Jan 07 '09 06:01

leo


People also ask

What is the difference between SQL joins?

Different Types of SQL JOINs (INNER) JOIN : Returns records that have matching values in both tables. LEFT (OUTER) JOIN : Returns all records from the left table, and the matched records from the right table. RIGHT (OUTER) JOIN : Returns all records from the right table, and the matched records from the left table.

What are the 4 types of joins in SQL?

There are four main types of JOINs in SQL: INNER JOIN, OUTER JOIN, CROSS JOIN, and SELF JOIN.

What are the 3 types of joins?

Basically, we have only three types of joins: Inner join, Outer join, and Cross join. We use any of these three JOINS to join a table to itself.

How many joins Are there any differences?

There are four main types of joins: inner join, full outer join, left outer join and right outer join. The major difference between inner and outer joins is that inner joins result in the intersection of two tables, whereas outer joins result in the union of two tables.


2 Answers

Check this article:

A Visual Explanation of SQL Joins

Inner Join:

Left Outer Join:

Right Outer Join:

like image 150
Christian C. Salvadó Avatar answered Oct 05 '22 19:10

Christian C. Salvadó


Performance comparisions between types of joins are irrelevant as they give differnt results sets. Even if an inner join is faster you wouldn't use it if you needed the results of a left join (which includes even the records which don't match the second table in the join).

like image 33
HLGEM Avatar answered Oct 05 '22 19:10

HLGEM