Introducing DotNetFunda.com on mobile http://m.dotnetfunda.com ! Be with DotNetFunda.com on the go !
Go to DotNetFunda.com
Twitter TwitterLinkedIn
YouTubeGoogle
 Online : 2401 |  Welcome, Guest!   Register  Login
Home > Articles > Sql Server > Join Multiple Tables In SQL

Join Multiple Tables In SQL

Article posted by Abhisek on 11/27/2009 | Views: 4387 | Category: Sql Server | Level: Beginner red flag


This article describes about how you can join different tables in SQL. It describes different join operations.

Combining Tables


         A query result can include data from multiple tables. To combine data from multiple tables, you can use the JOIN operation from SQL. The JOIN operation matches the rows of one table with rows of another table, based on values in those rows.


Types of JOIN



1. Inner Join
2. Outer Join
        Left-Outer Join
        Right-Outer Join
        Full-Outer Join
3. Cross Join

INNER JOIN
SELECT table1.col, table1.col, table2.col, table2.col FROM table1 INNER JOIN table2 ON table1.col = table2.col

    
      It is a join that displays only the rows that have a match in both the joined tables.

      This is the default type of join in Query Designer.

      Columns containing NULL do not match any values when you are creating an inner join and are excluded from the result set. NULL values do not match other NULL values.

LEFT OUTER JOIN

SELECT table1.col, table1.col, table2.col, table2.col FROM table1 LEFT OUTER JOIN table2 ON table1.col = table2.col


         It is a join  that includes rows even if they do not have related rows in the joined table.

         All rows from the first named table(the "left" table, which appears leftmost in the JOIN clause) are included. Unmatched rows in the right table do not appear.

         For every unmatched record a NULL value will appear for the rightmost table.

RIGHT OUTER JOIN
SELECT table1.col, table1.col, table2.col, table2.col FROM table1 RIGHT OUTER JOIN table2 ON table1.col = table2.col


          It is a join that includes rows even if they do not have the related rows in the joined table.

          All the rows from the second-named table(the "right" table, which appears rightmost in the JOIN clause) are included. Unmatched rows in the left table do not appear.

         For every unmatched record a NULL value will appear in the leftmost table.

FULL OUTER JOIN
SELECT table1.col, table1.col, table2.col, table2.col FROM table1 FULL OUTER JOIN table2 ON table1.col = table2.col

          It is a join that includes rows even if they do not have related rows in the joined table.

          All rows in all joined tables are included, whether they are matched or not.

         For every unmatched record a NULL value will appear for the corresponding table.

CROSS JOIN
SELECT*FROM table1 CROSS JOIN table2

It is a join whose result set includes one row for each possible pairing of rows from the two tables.


If you like this article, subscribe to our RSS Feed. You can also subscribe via email to our Interview Questions, Codes and Forums section.

Page copy protected against web site content infringement by Copyscape
Found interesting? Add this to:



Please Sign In to vote for this post.

Experience:0 year(s)
Home page:
Member since:Sunday, October 11, 2009
Level:Bronze
Status: [Member]
Biography:Thanks and Regards
Abhisek Panda
Go Green And Save Your Future
>> Write Response - Respond to this post and get points
Related Posts

The IDENTITY columns are auto incrementing columns provided by SQL Server. There can only be one IDENTITY column per table. SQL Server will take care of incrementing this column automatically.

Hi all, Here how you can get all the stored procedure from a database. Hey not only the name but the stored procedures definitions also.

This article explains the TOP with TIES clause.

Retrieving Column Names of a table from database using SQL

This is part 36 of the series of article on SSIS. In this article we are going to see on how to use an Aggregate (Maximum) data flow transformation control in SSIS packaging.

More ...
About Us | Contact Us | The Team | Advertise | Software Development | Write for us | Testimonials | Privacy Policy | Terms of Use | Link Exchange | Members | Go Top
General Notice: If you found plagiarised (copied) contents on this page, please let us know the original source along with your correct email id (to communicate) for further action.
Copyright © DotNetFunda.Com. All Rights Reserved. Copying or mimicking the site design and layout is prohibited. Logos, company names used here if any are only for reference purposes and they may be respective owner's right or trademarks. | 5/21/2012 7:23:56 AM