Using SQL’s IN syntax to search multiple fields

Josh Sherman
1 min read
Software Development SQL

This may not be something new for anyone, but figured I’d post it anyway. I needed to check for a certain date in multiple fields, instead of listing each one out, I used IN but used the value on the left side, and listed the fields in the parenthesis.


FROM table
WHERE date1 = "1981-02-23",
   OR date2 = "1981-02-23",
   OR date3 = "1981-02-23",
   OR date4 = "1981-02-23",
   OR date5 = "1981-02-23";


FROM table
WHERE "1981-02-23" IN (date1, date2, date3, date4, date5);
Join the Conversation

Good stuff? Want more?

Weekly emails about technology, development, and sometimes sauerkraut.

100% Fresh, Grade A Content, Never Spam.

About Josh

Husband. Father. Pug dad. Musician. Founder of Holiday API, Head of Engineering and Emoji Specialist at Mailshake, and author of the best damn Lorem Ipsum Library for PHP.

Currently Reading

Parasie Eve

Previous Reads

Buy Me a Coffee Become a Sponsor

Related Articles