First things first, before I show you an example, I will tell you the most common types SQL JOINs you can have:
INNER JOIN:
This will return all rows when there is at least one match in both tables.
LEFT JOIN: This will return all rows from the left table, and the matched rows from the right table.
RIGHT JOIN:
This will return all rows from the right table, and the matched rows from the left table.
FULL JOIN:
This will return all rows when there is a match in at least one of the tables.
The most common type of all the JOINS is the INNER JOIN or a simple join. This is the example I will be showing you more of today.
|
|
Now, lets JOIN these two tables with a SQL Select Statement.
Select Customer.ID as CustomerID, Name, OrderID, Date, Amount from Customer
INNER JOIN
Orders on Orders.CustomerID = Customer.ID;
The results to this statement will produce the results below. | ||||
---|---|---|---|---|
CustomerID | Name | OrderID | Date | Amount |
2 | Turgat | 1001 | 1-1-2015 | $100 |
4 | Kroogers | 1002 | 1-4-2015 | $400 |
2 | Turgat | 1003 | 1-6-2015 | $200 |
3 | Mojulrs | 1004 | 1-6-2015 | $100 |
Please note, several operators can be used to join tables, such as =, <, >, <>, <=, >=, BETWEEN, LIKE, and NOT, just to name a few. However, the most common operator is the equal symbol.
If you like this post and want to see more, follow me on my website www.chadcompton.com
Or if you prefer...
No comments:
Post a Comment
Drop me a line.