SQL Inner JOIN By Two Columns Tricky Example

Here is SQL Inner Join example of two tables. The first thing you need is common key for both tables. That means common fields of both the tables on which you are going to join. If you know table structure of both the tables, it is very easy to find Key field, and you can write join SQL query easily.

SQL Inner JOIN By Two Columns Tricky Example

Tricky SQL Inner Join Example Query

Here you can join Customer_Table and Order_Table using common keys. Here is you can find inner vs outer join differences and which is better.

SELECT
Customer_Number
,a.Customer_Name
,b.Order_Number
,b.Order_Total
FROM Customer_Table a
INNER JOIN
Order_Table b
Using (Customer_Number, phone_number) ;

Bottomline

  • I used here two tables. One is customer_table and the other one is order_table. Now know the key fields so you can complete your query easily.
  • Key is: using(customer_number, PHONE_NUMBER)
  • The columns in the using are common to both the tables.

Related Posts

SQL JOIN With Using

SQL Join Tables USING Vs ON

Two top methods to JOIN tables with Using and ON. Here are useful SQL queries to understand quickly.

Author: Srini

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