Select statement with multiple 'where' fields using same value without duplicating text

Posted by kdbdallas on Stack Overflow See other posts from Stack Overflow or by kdbdallas
Published on 2010-03-11T20:37:28Z Indexed on 2010/03/11 20:39 UTC
Read the original article Hit count: 254

Filed under:
|

I will start by saying that I don't think what I want can be done, but that said, I am hoping I am wrong and someone knows more than me. So here is your chance... Prove you are smarter than me :)

I want to do a search against a SQLite table looking for any records that "are similar" without having to write out the query in long hand.

To clarify this is how I know I can write the query:

select * from Articles where title like '%Bla%' or category like '%Bla%' or post like '%Bla%'

This works and is not a huge deal if you are only checking against a couple of columns, but if you need to check against a bunch then your query can get really long and nasty looking really fast, not to mention the chance for typos. (ie: 'Bla%' instead of '%Bla%')

What I am wondering is if there is a short hand way to do this?

*This next code does not work the way I want, but just shows kind of what I am looking for

select * from Articles where title or category or post like '%Bla%'

Anyone know if there is a way to specify that multiple 'where' columns should use the same search value without listing that same search value for every column?

Thanks in advance!

© Stack Overflow or respective owner

Related posts about sql

Related posts about sqlite