🔍
👶 Kids📝 Blog About Contact 🚀 Get Started Free

SQL – OR

Use OR in a WHERE clause to include a row when at least one of multiple conditions is true.

While AND is the strict condition (all must match), OR is the inclusive one. A row is included whenever at least one of the OR conditions is satisfied. It casts a wider net — perfect for scenarios like “show me students from Mumbai or Bangalore” without missing anyone from either city.

Be careful when mixing AND and OR without parentheses — SQL has operator precedence rules, and AND is evaluated before OR. Always use parentheses when combining them to make your intent perfectly explicit.

AND vs OR comparison

CityGradeAND resultOR result
MumbaiA
DelhiA
MumbaiC
DelhiC

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

  • OR includes rows where ANY one condition is true
  • Use IN() as a cleaner alternative to many OR conditions
  • Parentheses are critical: WHERE a=1 AND (b=2 OR c=3)
  • OR conditions can impact query performance — consider indexes

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.