I was wondering why do we use
where column=id
vs
where column in (id)
I know that the first will only allow a single id while the second will allow multiple ids, However why don’t we always use in even for a single column search?
In other words why do we not always use “where column in (id)”?
The two are essentially the same, so they are interchangeable. It is a personal preference which one to use.
Personally, I would use
=when I know I will never check for more than one value. I would useINif there’s a good chance I will modify the query later to add new values to the list.When performance isn’t a concern, instead of
IN, I sometimes useREGEXPas it more succinct, and requires less typing:or
Of course the less well known ‘null-safe’ equality operator
<=>:does not have an equivalent
INversion.