Praktikum Basis Data: Data Manipulation Language (DML)
Praktikum Basis Data: Data Manipulation Language (DML)
SELECT column_name(s)
FROM table1
INNER JOIN table2
ON table1.column_name = table2.column_name;
SELECT Orders.OrderID, Customers.CompanyName
FROM Orders
INNER JOIN Customers
ON Orders.CustomerID = Customers.CustomerID;
JOIN Three Tables
The following SQL statement selects all orders with
customer and shipper information:
SELECT Orders.OrderID,
Customers.CompanyName,
Shippers.CompanyName
FROM Orders INNER JOIN Customers
ON Orders.CustomerID = Customers.CustomerID
INNER JOIN Shippers
ON Orders.ShipVia = Shippers.ShipperID;
SELECT Orders.OrderID, Orders.OrderDate,
[Order Details].ProductID, Products.ProductName, [Order
Details].Quantity
FROM Orders INNER JOIN [Order Details]
ON Orders.OrderID = [Order Details].OrderID
INNER JOIN Products
ON [Order Details].ProductID = Products.ProductID
SQL LEFT JOIN Keyword
The LEFT JOIN keyword returns all rows from the left table (table_name1),
even if there are no matches in the right table (table_name2).
SELECT column_name(s)
FROM table1
LEFT JOIN table2
ON table1.column_name = table2.column_name;
SELECT Customers.CompanyName, Orders.OrderID
FROM Customers LEFT JOIN Orders
ON Customers.CustomerID = Orders.CustomerID
ORDER BY Customers.CompanyName;
SELECT A.ProductID, A.ProductName, A.UnitPrice,
B.CompanyName, B.ContactName
FROM Products AS A LEFT JOIN Suppliers AS B
ON A.SupplierID = B.SupplierID
SELECT column_name(s)
FROM table1
RIGHT JOIN table2
ON table1.column_name = table2.column_name;
SELECT Orders.OrderID, Employees.LastName,
Employees.FirstName
FROM Orders RIGHT JOIN Employees
ON Orders.EmployeeID = Employees.EmployeeID
ORDER BY Orders.OrderID;
SELECT A.ProductID, A.ProductName, A.UnitPrice,
B.CompanyName, B.ContactName
FROM Products AS A RIGHT JOIN Suppliers AS B
ON A.SupplierID = B.SupplierID
Suppliers are
included whether
or not they have
associated
Products
SQL FULL JOIN Keyword
The FULL OUTER JOIN keyword return all records when there is a match in
either left (table1) or right (table2) table records.
SELECT column_name(s)
FROM table1
FULL OUTER JOIN table2
ON table1.column_name = table2.column_name
WHERE condition;
SELECT Customers.CompanyName, Orders.OrderID
FROM Customers FULL JOIN Orders
ON Customers.CustomerID=Orders.CustomerID
ORDER BY Customers.CompanyName;
SELECT A.ProductID, A.ProductName, A.UnitPrice,
B.CategoryID, B.CategoryName
FROM Products AS A FULL JOIN
Categories AS B ON A.CategoryID = B.CategoryID
A full join
combines the
behavior of the
left and right
outer joins.