SQL - INNER JOIN Example
The following SQL statement will return all customers with orders:
Example
SELECT Customers.CustomerName, Orders.OrderID
FROM Customers
INNER JOIN Orders
ON Customers.CustomerID=Orders.CustomerID
ORDER BY Customers.CustomerName;
Try it Yourself »
Note: The INNER JOIN keyword selects all rows from both tables as long as there is a
match between the columns. If there are rows in the "Customers" table that do not have matches in "Orders", these customers will NOT be listed.
Different SQL JOINs
Before we continue with examples, we will list the types of the different SQL JOINs you can use:
- INNER JOIN: Returns all rows when there is at least one match in BOTH tables.
- LEFT JOIN: Return all rows from the left table, and the matched rows from the right table.
- RIGHT JOIN: Return all rows from the right table, and the matched rows from the left table.
- FULL JOIN: Return all rows when there is a match in ONE of the tables.
SQL - NOT BETWEEN Operator with Text Value Example
The following SQL statement selects all products with a ProductName beginning with any of the letter NOT BETWEEN 'C' and 'M':
Subscribe to:
Posts (Atom)