Home  >  Article  >  Database  >  The difference between inner joins and outer joins in SQL

The difference between inner joins and outer joins in SQL

PHPz
PHPzforward
2023-09-13 12:29:091003browse

The difference between inner joins and outer joins in SQL

In this article, we will understand the difference between inner join and outer join in SQL.

Inner join

  • clause uses "INNER JOIN" and "JOIN".

  • It returns a combined tuple of two or more tables.

  • When there are no common attributes, the result is empty.

  • "INNER JOIN" works faster than "OUTER" if the number of tuples is larger JOIN'.

  • Used when detailed information about a specific property is required.

  • 'JOIN' and 'INNER JOIN' work the same way.

Syntax

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

Outer Join

  • Returns the combined tuple of the specified table.

  • Returns even if the "JOIN" condition fails.

  • You can use the clauses LEFT OUTER JOIN, RIGHT OUTER JOIN, FULL OUTER JOIN.

  • Does not depend on public properties.

  • If the property is empty , then NULL is placed instead of blank.

  • Compared with "INNER JOIN", "OUTER JOIN" is slower.

  • It is Use when complete information is required.

    li>
  • FULL OUTER JOIN and FULL JOIN clauses work the same way.

Syntax

SELECT *
FROM table_1 LEFT OUTER JOIN / RIGHT OUTER JOIN /
FULL OUTER JOIN / FULL JOIN table_2 ON
Table_1.column_name = table_2.column_name;

The above is the detailed content of The difference between inner joins and outer joins in SQL. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete