SQL Inner Natural Join Examples

by top54u.com 24 Feb, 2008
Spotlight.....

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.

 

Also see the examples of Joins in SQL:

Self Join in SQL

Joins using table aliases in SQL Server 2005

Joins In Sql Server 2005 

Spotlight.....

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: , , , , ,

Add comment


(Will show your Gravatar icon)  

  Country flag

[b][/b] - [i][/i] - [u][/u]- [quote][/quote]



Live preview

8/23/2008 8:46:52 PM

OUR SPONSORS[+ advertise here]
related videos.....
recent posts.....
top54u ezines.....