A
A
Akaero2018-03-16 10:32:16
Transact SQL
Akaero, 2018-03-16 10:32:16

How to choose query type (nested or join)?

Good afternoon, I'm studying nested queries, which in some cases are easily replaced by joining tables. How to determine which type to use?
Example

SELECT orderid
FROM Sales.Orders
WHERE empid IN
(SELECT E.empid
FROM HR.Employees AS E
WHERE E.lastname LIKE N'Д%');

VS
SELECT O.orderid
FROM HR.Employees AS E
JOIN Sales.Orders AS O
ON E.empid = O.empid
WHERE E.lastname LIKE N'Д%'

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
smirnoww, 2020-02-21
@smirnoww

enable statistics display - for I/O operations - runtime statistics. and execute both requests in turn on the messages tab in ssms statistics will be displayed. By comparing, you can choose the query that requires the least amount of disk or processor resources
set statistics io on
set statistics time on

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question