260 Part I EXAM PREPARATION a matching record
260 Part I EXAM PREPARATION a matching record in Sales? This example returns all the records in Person, and matching records in Sales where they exist. First, using a LEFT JOIN: SELECT FirstName, LastName, ProductID, QtyPurchased FROM Person LEFT JOIN Sales ON Person.PersonID = Sales.PersonID And then a RIGHT JOIN: SELECT FirstName, LastName, ProductID, QtyPurchased FROM Sales RIGHT JOIN Person ON Person.PersonID = Sales.PersonID These two queries both return exactly the same resultset, because the order of the tables is different. The LEFT JOIN example does Person LEFT JOIN Sales and the RIGHT JOIN example does Sales RIGHT JOIN Person. IN THE FIELD RIGHT JOIN AND LEFT JOIN As you ve just read, LEFT JOIN and RIGHT JOIN both do the same thing. Why does Transact-SQL include both, and which should you use? Typically, you should use LEFT JOIN whenever possible. There s no reason for this other than convention, and most Western languages read left to right, so people in Western cultures are more trained to think in that direction. So using LEFT JOIN will make your query easier for someone else to understand. In other order-related issues, the order that the ON clause is in does not change how the clause works. For example, saying ON P.PersonID = S.PersonID is the same as S.PersonID = P.PersonID. Now it s time to put together everything you ve learned so far. You ve got an INNER JOIN and an OUTER JOIN. You can use table aliases in an OUTER JOIN the same way as you do in an INNER JOIN, by the way. Table aliasing is a feature of the FROM clause, not the
For high quality java hosting services please check tomcat web hosting website.