SQL: SELECT IN is faster and better?

if i m uses 2 queries:

first: asks for all required keys / identifiers

second: select * from tab1, where tab1.id is in (... ids list ..,)

the list of identifiers can be several thousand ...

Is it wisdom or best practice or is it recommended to do such things?

+3
source share
2 answers

It is generally ideal for using the IN clause in your statements ... given that you are using a subquery for larger sets of values.

: ! , SELECT, . , ( ), . .

    SELECT * FROM Customer 
    WHERE CustomerID IN (SELECT ID FROM MyOtherLargeTableOfCustomers)
  • , IN?
  • ? , .
  • STATISTICS ( SQL Server).
  • char , , , , .
  • JOIN ; .
SELECT * FROM Customer AS C 
INNER JOIN MyOtherLargeTableOfCustomers AS M
ON C.CustomerID = M.CustomerID
+7

, , db.

+1

Source: https://habr.com/ru/post/1714181/


All Articles