SQL Queries Joining two Tables with ‘USING’ and ‘ON’

Here are two tables. One is Customer_table and the other one is Order_table.

Here, the joining method is INNER JOIN. That means joining is based on matching of both the tables.

JOIN SQL Query with ‘Using’

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.

JOIN SQL 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;

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

Author: Srini

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