0% found this document useful (0 votes)
13 views

SQL JOINS

Uploaded by

Phia Arquero
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views

SQL JOINS

Uploaded by

Phia Arquero
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 28

SQL JOINS

SELECT Orders.OrderID, Customers.CustomerName,


Orders.OrderDate
FROM Orders
INNER JOIN Customers ON
Orders.CustomerID=Customers.CustomerID;
The SQL JOIN is a command clause that combines records from
two or more tables in a database. It is a means of combining data
in fields from two tables by using values common to each table. If
you're working with databases, at some point in your work you will
likely need to use SQL JOINs.
SQL JOIN

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:
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;
Insert the missing parts in the JOIN clause to join the two tables Orders and Customers,
using the CustomerID field in both tables as the relationship between the two tables.

SELECT *
FROM Orders
LEFT JOIN Customers

Answer:
SELECT *
FROM Orders
LEFT JOIN Customers =;
Choose the correct JOIN clause to select all records from the two tables where there is a match in both tables.

SELECT *

FROM Orders

ON Orders.CustomerID=Customers.CustomerID;

ANSWER:

SELECT *
FROM Orders
ON Orders.CustomerID=Customers.CustomerID;
Choose the correct JOIN clause to select all the records from the Customers table plus all the
matches in the Orders table.

SELECT *

FROM Orders

ON Orders.CustomerID=Customers.CustomerID;

ANSWER:
SELECT *
FROM Orders
ON Orders.CustomerID=Customers.CustomerID;
inner join
left (Outer)
right (Outer)
full (Outer)
inner join

Inner joins combine records from two tables whenever there are
matching values in a field common to both tables. You can use INNER
JOIN with the Departments and Employees tables to select all the
employees in each department.

You might also like