question

Gehima2016 avatar image
Gehima2016 asked

four table join syntax

Hey Everyone, Please, check out the four table join query and see if it correct --Get SalesOrderID, CustomerID, TerritoryID and TotalDue for highest amount ordered in 2007 SELECT h.[SalesOrderID], c.[CustomerID], t.[TerritoryID], s.[CardNumber] FROM [Sales].[SalesOrderHeader] h LEFT JOIN [Sales].[Customer] c ON h.[CustomerID] = c.[CustomerID] LEFT JOIN [Sales].[SalesTerritory] t ON h.[TerritoryID] = t.TerritoryID LEFT JOIN [Sales].[CreditCard] s ON h.[CreditCardID] = s.CreditCardID WHERE [TotalDue] = (SELECT max([TotalDue]) FROM [Sales].[SalesOrderHeader] WHERE YEAR([OrderDate]) = 2007) --joined these four tables to display SalesOrderID, CustomerID, TerritoryID and credit card number for highest amount ordered in 2007 --The [Sales].[SalesOrderHeader] is the main table that has CustomerID, TerritoryID, CreditCardID as foreign key on the table. --CustomerId column is a foreign key in the [Sales].[SalesOrderHeader] table is used to join CustomerId column which is a primary in --[Sales].[Customer] table. --TerritoryID column is a foreign key in the [Sales].[SalesOrderHeader] table is used to join TerritoryID column which is a primary in --[Sales].[SalesTerritory] table. --CreditCardID column is a foreign key in the [Sales].[SalesOrderHeader] table is used to join TerritoryID column which is a primary in --[Sales].[CreditCard] table and the credit card number is retrieved from this table to the result set.
tablejoinsyntax
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

0 Answers