How To Write SQL Server Queries Correctly: EXISTS and NOT EXISTS

Опубликовано: 16 Март 2026
на канале: Erik Darling (Erik Darling Data)
2,812
205

In this video, I delve into the often overlooked and underused SQL Server features: 'EXISTS' and 'NOT EXISTS'. These powerful directives can significantly improve query performance and reduce duplication in results. I share practical examples of how using these clauses can transform your queries from cumbersome and inefficient to elegant and efficient. Along the way, we also tackle common misconceptions about their usage, such as the belief that what you select within an 'EXISTS' clause affects its performance-something I debunk by demonstrating that it doesn't matter at all! Additionally, I discuss how these clauses can be used effectively in scenarios involving one-to-many or many-to-many relationships and explore why using a 'LEFT JOIN' for certain queries might not always be the best approach. By the end of this video, you'll have a better understanding of when to use 'EXISTS' and 'NOT EXISTS', and how they can streamline your SQL coding process.

CHAPTERS

00:00:00 - Introduction
00:01:59 - Become a Member
00:04:34 - Exists and Not Exists
00:06:54 - SQL Rules and Challenges
00:08:09 - Query Example
00:12:03 - Correct Exists Queries
00:15:11 - Table Relationships
00:17:29 - Performance Comparison
00:19:34 - Non-Correlated Subqueries

━━━━━━━━━━━━━━━━━━━━━━━━━━
📚 TRAINING & COURSES
━━━━━━━━━━━━━━━━━━━━━━━━━━
Get AI-Ready With Erik
https://training.erikdarling.com/get-...

SQL Server Performance Engineering Course
https://training.erikdarling.com/sql-...

Learn T-SQL with Erik
https://training.erikdarling.com/lear...

Everything Bundle:
https://training.erikdarling.com/?cou...

━━━━━━━━━━━━━━━━━━━━━━━━━━
🛠️ CONSULTING & SERVICES
━━━━━━━━━━━━━━━━━━━━━━━━━━
Need SQL Server performance help?
https://training.erikdarling.com/sqlc...

━━━━━━━━━━━━━━━━━━━━━━━━━━
💬 CONNECT
━━━━━━━━━━━━━━━━━━━━━━━━━━
Ask questions at Office Hours
https://erikdarling.com/officehours/

Become a channel member
   / @erikdarlingdata  
━━━━━━━━━━━━━━━━━━━━━━━━━━