How to write Query to Join 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

SELECT

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

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

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.