SQL Join Tables with Multiple Conditions

SQL Query Join Two Tables Example

Here is Join SQL Query example for two tables. The first thing you need to know 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.

JOIN SQL Query for Two Tables

Here you can join Customer_Table and Order_Table using common keys.

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

You can find inner vs outer join differences and which is better.

Takeaway

  • I used here two tables. One is customer_table and the other one is order_table. So, if you know the key field you can easily complete your query.
  • Key is: using(customer_number),
  • The column in the using is common to both the tables. Now you can write any join query quickly.

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.