Home > Database > SQL > body text

What is the difference between left link and right link in sql

下次还敢
Release: 2024-05-02 00:12:15
Original
1046 people have browsed it

The left link retains the left table rows, and the right link retains the right table rows. A left join fills NULL in left table rows that have no matching rows in the right table, while a right join fills NULLs in right table rows that have no matching rows in the left table.

What is the difference between left link and right link in sql

The difference between left link and right link in SQL

In SQL, both left link and right link are Common operations for joining tables, but they differ significantly in how data is retrieved.

Left link

  • Preserves all rows from the left table, even if there are no matching records in the right table.
  • For left table rows that have no matching records in the right table, the value of the right table column will be displayed as NULL.
  • Query syntax:

    SELECT *
    FROM left_table
    LEFT JOIN right_table
    ON left_table.key = right_table.key;
    Copy after login

Right link

  • Retain all rows in the right table, Even though there are no matching records in the left table.
  • For right table rows that have no matching records in the left table, the value of the left table column will be displayed as NULL.
  • Query syntax:

    SELECT *
    FROM right_table
    RIGHT JOIN left_table
    ON left_table.key = right_table.key;
    Copy after login

Main difference

  • Reserved rows: The left link retains the left table rows, and the right link retains the right table rows.
  • NULL values: Left joins fill NULL in left table rows that have no matching rows in the right table, while right joins fill NULLs in right table rows that have no matching rows in the left table.

The above is the detailed content of What is the difference between left link and right link in sql. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!