![]() ![]() ORDER BY oh.OrderDate, oh.SalesOrderID, od.SalesOrderDetailID Replace the query with the following code, which retrieves sales order data from the SalesLT.SalesOrderHeader, SalesLT.SalesOrderDetail, and SalesLT.Product tables: SELECT oh.OrderDate, oh.SalesOrderNumber, p.Name As ProductName, od.OrderQty, od.UnitPrice, od.LineTotal The use of table aliases can greatly simplify a query, particularly when multiple joins must be used. Run the modified query and confirm that it returns the same results as before. ON p.ProductCategoryID = c.ProductCategoryID Modify the query to assign aliases to the tables in the JOIN clause, as shown here: SELECT p.Name As ProductName, c.Name AS Category INNER joins are the default kind of join. The results should be the same as before. Modify the query as follows to remove the INNER keyword, and re-run it. Because the query uses an INNER join, any products that do not have corresponding categories, and any categories that contain no products are omitted from the results. Use the ⏵Run button to run the query, and and after a few seconds, review the results, which include the ProductName from the products table and the corresponding Category from the product category table. In the query editor, enter the following code: SELECT As ProductName, AS Category
0 Comments
Leave a Reply. |