What is the difference between IN and EXISTS, and which is generally more efficient?

Last updated 3 July 2026

  • IN compares a value against a returned list, suiting small distinct sets. EXISTS checks whether any row exists and short-circuits on the first match, suiting large or correlated subqueries.

  • NULL trap: NOT IN returns no rows if the list contains a NULL, while NOT EXISTS behaves predictably.

  • Modern optimizers often produce the same plan for both, so data shape and NULL handling matter more than the keyword.

  • https://dev.mysql.com/doc/refman/8.3/en/subquery-optimization-with-exists.html
  • https://dev.mysql.com/blog-archive/new-optimizer-hints-in-mysql/
  • https://dev.to/franckpachot/not-in-executed-as-an-anti-join-not-exists-in-pg19-3gga
  • https://dev.mysql.com/worklog/task/?id=13377
  • https://medium.com/@tolgayildiz91/in-vs-exists-is-in-really-slower-or-just-a-developer-myth-e3263755919b
  • https://medium.com/@workwithalam/in-vs-exists-in-sql-whats-the-difference-when-to-use-which-f489e6012bf3
  • https://medium.com/@mk.muhammadkhoirudin/in-vs-exists-in-sql-same-result-but-different-behavior-d01f748cc607
  • https://dev.to/mdarifulhaque/in-vs-exists-in-sql-understanding-performance-and-usage-585d
All SQL interview questions