MySQL SQLLesson 25Free preview
MySQL IN
This lesson is part of MySQL · All levels
Summary
The IN operator checks whether the value of a column matches one of the values from a list. In many cases, IN becomes a more neat alternative to writing many OR conditions, e.g. IN city ('Jakarta', 'Bandung', 'Surabaya'). You can also use the subquery on the right side of IN so that the list of values is generated from another query, and then reverse it with NOT IN.
Key points
- IN checks the membership of values in the list written in parentheses
- Logically equivalent to a simplified OR sequence
- Subquery can be used on the right side of IN to build a value list
- NOT IN takes values off the list, but be careful when the list contains NULL
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.