
Answer-first summary for fast verification
Answer: SELECT * FROM Orders INNER JOIN Customers ON Orders.CustomerID = Customers.CustomerID WHERE OrderDate >= DATEADD(year, -1, GETDATE());
The most efficient query is the one that performs the join and the filter in a single step, which is option A. This query ensures that the join is performed only on the relevant subset of data (orders from the last year), reducing the amount of data processed and improving performance.
Author: LeetQuiz Editorial Team
Ultimate access to all questions.
You are working with Azure Synapse Analytics and need to transform data using Transact-SQL (T-SQL). The task involves joining two large tables, 'Orders' and 'Customers', on the 'CustomerID' field and then filtering the results to include only orders placed in the last year. Which T-SQL query would be most efficient for this task, considering the size of the tables and the need for performance optimization?
A
SELECT * FROM Orders INNER JOIN Customers ON Orders.CustomerID = Customers.CustomerID WHERE OrderDate >= DATEADD(year, -1, GETDATE());
B
SELECT * FROM Orders, Customers WHERE Orders.CustomerID = Customers.CustomerID AND OrderDate >= DATEADD(year, -1, GETDATE());
C
SELECT * FROM Orders INNER JOIN Customers ON Orders.CustomerID = Customers.CustomerID;
D
SELECT * FROM Orders WHERE OrderDate >= DATEADD(year, -1, GETDATE());
No comments yet.