General Note:

Here we have pulled in the data from a sample database. You can download it from the following link and use it for practicing Click Here For Sample Database

Natural join writes its own join condition based on the common column name in the both table. Both table has mobile name column. So natural join takes mobile_name column to write condition. The condition looks like Mobile_sales_detail.mobile_name=mobile_rating.mobile_name



Select mobile_sales_details.mobile_name, price, brand_name, star5 from mobile_sales_details natural join mobile_rating

 

mobile_name             price       brand_name star5    

---------------------- ---------- ---------- ----------

Moto X (16 GB) (Black) 23999       Motorola   20072    

Moto G (Black with 16 13999       Motorola   2078    

Moto E (Black)         6999        Motorola   12900    

Asus Zenfone 4 A400CG   5999       Asus       195      

Asus Zenfone 5 A501CG   9999       Asus       465      

Asus Zenfone 5 A501CG   12999       Asus       114      

Asus Zenfone 6 A600CG   16999       Asus       74        

Alcatel Onetouch Idol   16999       Alcatel     368      

Samsung Galaxy S Duos   8206       Samsung     981      

Samsung Galaxy Star Pr 7599       Samsung     348      

Samsung Galaxy S Duos   8214       Samsung     981      

Samsung Galaxy Core I8 11795       Samsung     516      

Samsung Galaxy Grand 2 18990       Samsung     393      

Samsung Galaxy Trend S 9610       Samsung     128      

Samsung Galaxy Grand N 14010       Samsung     38      

Samsung I8552 - Galaxy 15999      Samsung     574      

Samsung Galaxy S4 Mini 24730       Samsung     216      

Samsung GT 1200 R/I/M   1299       Samsung     8        

Samsung Guru 1200 (Bla 1399       Samsung     613      

Samsung Galaxy S5 (Cha 54300       Samsung     184

We have mobile names and their price in one table and rating of those mobiles in another table. The above query used to join that two table to retrieve mobile name and their 5 star ratings.

USING KEYWORD:

If you have more than one column with same name, we can not apply natural join. Since, natural join takes one same column name only. So to avoid this problem we have "using" keyword.

Let us look at the below query. Just consider we have two columns with same name in both table (actually we do not have two same column name in both table). To avoid confusion we are using the "using" keyword and mentioning which column the join query have to use. It will produce same result as above query. However, the only difference is here we are using the "using" keyword with specific column name.



Select mobile_name, price, brand_name, star5 from mobile_sales_details join mobile_rating using (mobile_name)

 

mobile_name             price       brand_name star5    

---------------------- ---------- ---------- ----------

Moto X (16 GB) (Black)  23999       Motorola   20072    

Moto G (Black with 16   13999       Motorola   2078    

Moto E (Black)          6999       Motorola   12900    

Asus Zenfone 4 A400CG   5999       Asus       195      

Asus Zenfone 5 A501CG   9999       Asus       465      

Asus Zenfone 5 A501CG   12999       Asus       114      

Asus Zenfone 6 A600CG   16999       Asus       74      

Alcatel Onetouch Idol   16999       Alcatel     368      

Samsung Galaxy S Duos   8206      Samsung     981      

Samsung Galaxy Star Pr 7599       Samsung     348      

Samsung Galaxy S Duos   8214       Samsung     981      

Samsung Galaxy Core I8 11795       Samsung     516      

Samsung Galaxy Grand 2 18990       Samsung     393      

Samsung Galaxy Trend S 9610       Samsung     128      

Samsung Galaxy Grand N 14010       Samsung     38      

Samsung I8552 - Galaxy 15999       Samsung     574      

Samsung Galaxy S4 Mini 24730       Samsung     216