Is there a way to check if multiple values exist in the same in clause, without rewriting the same IN clause?
Example
Employee Table:
+----+--------------+---------------+-------------+
| id | first_name | middle_name | last_name |
+----+--------------+---------------+-------------+
| 1 | Ian | Daniel | de Villiers |
| 2 | Karien | | Tolmie |
| 3 | John | Peter | Green |
| 4 | Daniel | Silie | von Guns |
| 5 | Francois | Roos | Krans |
+----+--------------+---------------+-------------+
Say I want all employees whos first, middle or last name is either Daniel or Peter - thus, I want ids 1, 3 and 4.
The only way I know how to do this is:
SELECT id
FROM employees
WHERE ( first_name IN ( "Daniel", "Peter" ) )
OR ( middle_name IN ( "Daniel", "Peter" ) )
OR ( last_name IN ( "Daniel", "Peter" ) )
This can be come quite long if I have multiple values to test or have excessive amounts of values in the IN clause.
I have tried
SELECT id
FROM employees
WHERE ( first_name OR middle_name OR last_name IN ( "Daniel", "Peter" ) )
but I think that will cause first_name to be interpreted as a boolean value.
where 'Daniel' in () or 'Peter' in ()first_name, middle_nameandlast_nameintofullnameand then query forsubstringsonfullname, this would simplify the query?danielis containedin ('dan', 'ielle', 'green')as the concatenation will bedaniellegreen, resulting in a false positive