JOIN ON is used to match rows between multiple tables by specified columns and return the connection results. The steps include: specifying the target table, the join type (INNER, LEFT, RIGHT, FULL) and the join condition (matching columns of both tables in the ON clause).
Usage of JOIN ON in SQL
Function of JOIN ON
JOIN ON is used to establish a join between multiple tables, match the values of specific columns, and return the join results as a new table.
Syntax structure
<code class="sql">SELECT 列1, 列2, ... FROM 表1 JOIN 表2 ON 表1.列名 = 表2.列名;</code>
Steps
The FROM
clause specifies the table or view to be joined. JOIN
The keyword specifies the connection type, such as INNER JOIN
, LEFT JOIN
, etc. ON
The clause specifies the conditions for the connection, that is, the columns to be matched in the two tables. Example
The following query uses JOIN ON
from the Customers
and Orders
tables Return customer information and order information in:
<code class="sql">SELECT Customers.CustomerID, Customers.CustomerName, Orders.OrderID, Orders.OrderDate FROM Customers JOIN Orders ON Customers.CustomerID = Orders.CustomerID;</code>
Connection type
SQL supports multiple connection types, including:
Best Practices
The above is the detailed content of How to use join on in sql. For more information, please follow other related articles on the PHP Chinese website!