Theme-Logo
  •   .Net
    •   C Sharp(C#)
    •   Web API
    •   Micro Services
    •   ASP.Net
    • ASP.Net MVC
    • .Net Core
  •   Database
    • SQL Server
    • Oracle
    • PostgreSQL
  •   jQuery
    • jQuery Tutorials
    • jQuery Plugins
    • jQuery UI
    • More on jquery
  •   Tutorials
    • Microservices Tutorials
    • DotNet Core Tutorials
    • PostgreSql Tutorials

Joins in SQL Server

Joins means combining. In SQL Server JOIN clause is used to combine rows from two or more tables, based on a related column between them. Please note that only JOIN clause behave like INNER JOIN in the most of RDBMS databases.

Example of Join

Lets we have ORDERS table somethings like:

OrderID CustomerID OrderDate
10308 2 1996-09-18
10309 37 1996-09-19
10310 77 1996-09-20
And we have another CUSTOMERS table like:
CustomerID CustomerName ContactName Country
1 Alfreds Futterkiste Maria Anders Germany
2 Ana Trujillo Emparedados y helados Ana Trujillo Mexico
3 Antonio Moreno Taquería Antonio Moreno Mexico

Notice that the CUSTOMERS column in the ORDERS table refers to the "CustomerID" in the "Customers" table. The relationship between the two tables above is the "CustomerID" column. Then, we can create the following SQL statement (that contains an INNER JOIN), that selects records that have matching values in both tables:

                                SELECT Orders.OrderID, Customers.CustomerName, Orders.OrderDate
                                FROM Orders
                                INNER JOIN Customers ON Orders.CustomerID=Customers.CustomerID;
                                

and it will produce something like this:

OrderID CustomerName OrderDate
10308 Ana Trujillo Emparedados y helados 9/18/1996
10365 Antonio Moreno Taquería 11/27/1996
10383 Around the Horn 12/16/1996
10355 Around the Horn 11/15/1996
10278 Berglunds snabbköp 8/12/1996

Types of Join

Here are the different types of the JOINs in SQL Server

  • INNER JOIN or JOIN: Returns records that have matching values in both tables
  • LEFT JOIN or LEFT OUTER JOIN : Returns all records from the left table, and the matched records from the right table
  • RIGHT JOIN or RIGHT OUTER JOIN: Returns all records from the right table, and the matched records from the left table
  • FULL JOIN or FULL OUTER JOIN: Returns all records when there is a match in either left or right table
  • :

    ❮ SQL Server
    NULL Values ❯

    Other Related Post
    Introduction of SQL Server.
    SQL Server Join.
    SQL Server Null values.
    SQL Server Union and Union All.
    The SQL INSERT INTO SELECT Statement.
    How to find top N salary of employee with different way.
    How to create indexes in sql server table.
    How to improve sql server stored procedure performance.
    Interview Questions and Answers
    What are the steps you will take to improve the performance of a poor performing query?
    What is a deadlock and what is a live lock? How will you go about resolving deadlocks?
    What structure can you implement for the database to speed up table reads?
    Could you please some items which you may see in an execution plan indicating the query is not optimized.
    About us

    DotNet Palace is a community platform created and maintained by The articles are mainly focused on Microsoft stack technologies like C#, ASP.Net, MVC, .Net Core, SQL Server and Oracle, PostgreSQL, SQLite etc. To improve the site's content you can send your valuable suggestions at info.dotnetpalace@gmail.com

    Quick links
  • SOLID Principles
  • Questions
  • OOPS Principles
  • DotNet Palace Tutorials
  • Privacy Policy
  • Terms and Condition