-
SQL Installing SSMS
-
SQL Syntax
-
SQL Datatype
-
SQL Database
-
SQL Table
-
SQL Select
-
SQL Distinct
-
SQL Count
-
SQL Top
-
SQL Aliases
-
SQL In
-
SQL Insert
-
SQL Update
-
SQL Null
-
SQL Like
-
SQL Wildcards
-
SQL Nested Query
-
SQL Between
-
SQL Unique
-
SQL Primary Key
-
SQL Foreign Key
-
SQL Check
-
SQL Default
-
SQL Database Diagram
-
SQL Stored Procedures
-
SQL Joins
-
SQL Inner Join
-
SQL Left Join
-
SQL Right Join
-
SQL Full Join
-
SQL Trigger
SQL Joins
A JOIN clause is used to combine rows from two or more tables, based on a related column between them.
Let’s look at a selection from the “Orders” table:
Then, look at a selection from the “Customers” table:
Notice that the “CustomerID” 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:
Different Types of SQL JOINS
Here are the different types of the JOINs in SQL:
– INNER JOIN: Returns records that have matching values in both tables
– LEFT (OUTER) JOIN: Returns all records from the left table, and the matched records from the right table
– RIGHT (OUTER) JOIN: Returns all records from the right table, and the matched records from the left table
– FULL (OUTER) JOIN: Returns all records when there is a match in either left or right table