Here are the differences between Using and ON in Join SQL query. Here are two sample tables – Customer_table and Order_table. You can see sample SQL to join these tables using both USING and ON.
Here the joining method is INNER JOIN ( joining is based on matching column of both the tables).
How to use Using to in SQL query to Join tables
Here join condition is customer_number.
SELECT
Customer_Number
,Customer_Name
,Order_Number
,Order_Total
FROM Customer_Table
INNER JOIN
Order_Table
Using (Customer_Number) ;
Here the ‘using, clause works as ‘on’. So the joining happens based on the column name given in the using clause.
How to use ON in SQL query to Join Tables
SELECT
Customer_Number
,Customer_Name
,Order_Number
,Order_Total
FROM Customer_Table a
INNER JOIN
Order_Table b
ON a.Customer_Number = b.Customer_Number;
Here the ‘ON’ clause is used to join tables.
Differences Between USING and ON
In the Using, you can give multiple columns in simple way:
using(col1, col2, col3)
In the case of ON:
ON a.col1=b.col1
AND a.col2=b.col2;
Related Posts