Searching multiple columns using WHERE
Is this possible:
Select * FROM users WHERE * LIKE %%searchterm%%
Basically, I want to search multiple columns rather than a single one. Lisiting the column names individually and separating them by commas, 'AND', or 'OR' returns a syntax error.
Thanks for any help.
need to work with multiple columns separated by 'OR' or 'AND'
select * from table where col1 like '%searchterm%' or col2 like '%searchterm%' or col3 like '%searchterm%';
some dbms also provide simpler solutions for this instead of an or. in mysql you can use its full text search. you can try using a concat in oracle as well.
As Chazzy points out, different databases offer different alternatives.
What database you using?
mysql search multiple columns
in case there are fixed number of columns you are looking into, a revert of SQL IN statement will do the trick, an example can be seen here http://alltips.in/mysql-search-multiple-columns/
And engines as well. MSSQL also have full text search.
Originally Posted by chazzy
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)