SQL Inner Natural Join Examples
In the previous article you learnt how to use equi inner join in sql queries to join two tables and retrieve the combined result of both sql database tables. See the example of equi join here… SQL Inner Equi Join Examples. Notice that equi join sql query returned the categoryId column twice because of relation between two tables. Products table also has categoryId column that shows the product belongs to a particular category in categories whose categoryId is also saved in products table as a relational key between both the tables.
You can specify the required column names using sql natural join query.
Natural Join Query Example
SELECT C.*, P.PRODUCTID, P.PRODUCTNAME FROM CATEGORIES C INNER JOIN PRODUCTS P ON P.CATEGORYID = C.CATEGORYID
This natural join query will return all the columns of categories table and prodcutId and productName from products table.
You can further modify this natural inner join query as per your requirements to visualize the data by specifying the column names of categories table also.
Inner Join Query Example by Specifying Column Names
SELECT C.CATEGORYID, C.CATEGORYNAME, P.PRODUCTID, P.PRODUCTNAME, P.UNITPRICE FROM CATEGORIES C INNER JOIN PRODUCTS P ON P.CATEGORYID = C.CATEGORYID
This inner join query will display only the specified column names of both the tables.
Note: In actual SQL Server does not support natural joins. This type of Inner Join is considered as equivalent to the natural join.
Continue to next tutorial: SQL Inner Join Examples to learn the implementation of inner join.
