乐闻世界logo
搜索文章和话题

What is the default MySQL JOIN behaviour, INNER or OUTER?

1个答案

1

By default, MySQL uses INNER JOIN for JOIN operations. When using the JOIN keyword without explicitly specifying the JOIN type, it defaults to INNER JOIN. INNER JOIN returns only the matching rows between the two tables, excluding any rows that lack a corresponding match in the other table.

Suppose we have two tables: the employees table and the departments table. Each employee row contains a department ID that references the corresponding department in the departments table.

sql
SELECT employees.name, departments.department_name FROM employees JOIN departments ON employees.department_id = departments.id;

In this query, as no JOIN type is specified, it defaults to INNER JOIN. Consequently, only employees with a valid department ID that exists in the departments table are included in the results. If an employee's department ID does not match any entry in the departments table, their details will not be returned.

2024年8月7日 00:04 回复

你的答案