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':
SQL - BETWEEN Operator with Text Value Example
The following SQL statement selects all products with a ProductName beginning with any of the letter BETWEEN 'C' and 'M':
SQL - BETWEEN Operator with IN Example
The following SQL statement selects all products with a price BETWEEN 10 and 20, but products with a CategoryID of 1,2, or 3 should not be displayed:
Example
SELECT * FROM Products
WHERE (Price BETWEEN 10 AND 20)
AND NOT CategoryID IN (1,2,3);
Try it Yourself »
SQL - NOT BETWEEN Operator Example
To display the products outside the range of the previous example, use NOT BETWEEN:
Subscribe to:
Posts (Atom)