SQL Join: How to Use ‘USING’ and ‘ON’ Clauses

You can find here Two tables. One is Customer_table and the other one is Order_table.

Here, we applied INNER JOIN. That means matching of both the tables. The joining condition you can give with ‘USING’ keyword and its column name.

How to Use the ‘Using’ Clause in SQL Join Query

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) ;

In the above query , the ‘using, clause works as ‘on’. So you are joining the tables based on the column name given in the using clause.

How to Write the Query With ON

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;

In the above query, the ‘ON’ clause will be used to join the Tables.

Real Differences of 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

Author: Srini

Experienced software developer. Skills in Development, Coding, Testing and Debugging. Good Data analytic skills (Data Warehousing and BI). Also skills in Mainframe.