🔍
👶 Kids📝 Blog About Contact 🚀 Get Started Free

SQL – IN

Filter rows matching any value from a list using the IN operator — a cleaner alternative to multiple OR conditions.

The IN operator lets you check whether a column value matches any item in a list. It is syntactic sugar — WHERE city IN ('Mumbai', 'Delhi', 'Pune') is equivalent to WHERE city = 'Mumbai' OR city = 'Delhi' OR city = 'Pune' — but far more readable, especially when the list is long.

IN can also accept a subquery as its list — making it one of the most powerful filtering tools in SQL. WHERE id IN (SELECT student_id FROM enrollments WHERE status = 'active') finds exactly the students with active enrollments without writing a join.

IN with list vs. subquery

-- Static list
WHERE grade IN ('A', 'B')

-- Dynamic subquery
WHERE id IN (
  SELECT student_id FROM enrollments
  WHERE final_score > 90
)

Try It Yourself — Interactive SQL Editor

Edit the query below and click Run Query ▶ to see live results powered by SQLite running directly in your browser.

SQLite – edit & run
Results
← Click Run Query ▶ to see results

Key Points

  • IN is cleaner than multiple OR conditions for same-column checks
  • NOT IN excludes all listed values
  • IN with a subquery is extremely powerful (correlated subqueries)
  • NULL in an IN list can cause unexpected behavior — always handle NULLs explicitly

Pro Tip from CodesCompiler: The best way to learn SQL is to break things intentionally — modify the query above, change the WHERE conditions, try different columns. Every error teaches you something the docs cannot.

In the next lesson, we continue exploring SQL’s powerful feature set to build your database mastery.