Which method of T-SQL is better for performance LEFT JOIN or NOT IN when writing query? Answer is : It depends! It all depends on what kind of data is and what kind query it is etc. In that case just for fun guess one option LEFT JOIN or NOT IN. If you need to refer the query which demonstrates the mentioned clauses, review following two queries.
USE AdventureWorks;
GO
SELECT ProductID
FROM Production.Product
WHERE ProductID
NOT IN (
SELECT ProductID
FROM Production.WorkOrder);
GO
SELECT p.ProductID
FROM Production.Product p
LEFT JOIN Production.WorkOrder w ON p.ProductID = w.ProductID
WHERE w.ProductID IS NULL;
GO
Reference : Pinal Dave (http://www.SQLAuthority.com)
Tuesday, May 27, 2008
Better Performance - LEFT JOIN or NOT IN?
Gostou deste artigo? Deixe um comentário ou assine nosso Feed.
Artigos Relacionados
- COMMON SQL PROBLEMS
- Ordering in SQL
- How to Read Statistics Profile in SQL
- C++ Programming (Part 1)
- Better Performance - LEFT JOIN or NOT IN?
- SQL SERVER Database Coding Standards and Guidelines Complete List Download
- Delete Duplicate Records - Rows - Readers Contribution
- Four Basic SQL Statements - SQL Operations
Subscribe to:
Post Comments (Atom)
seja o primeiro a comentar!