dcsimg
www.webdeveloper.com
Results 1 to 6 of 6

Thread: Searching multiple columns using WHERE

  1. #1
    Join Date
    Mar 2006
    Posts
    6

    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.

  2. #2
    Join Date
    Mar 2006
    Posts
    52

    Lightbulb

    need to work with multiple columns separated by 'OR' or 'AND'

    just try:

    select * from table where col1 like '%searchterm%' or col2 like '%searchterm%' or col3 like '%searchterm%';

    Best Regards
    A.

  3. #3
    Join Date
    Aug 2005
    Location
    The Garden State
    Posts
    5,634
    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.

  4. #4
    Join Date
    Mar 2006
    Location
    NCAA Tournament Hell
    Posts
    21
    As Chazzy points out, different databases offer different alternatives.

    What database you using?

  5. #5
    Join Date
    Nov 2009
    Posts
    2

    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/

  6. #6
    Join Date
    Oct 2009
    Posts
    658
    Quote Originally Posted by chazzy View Post
    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.
    And engines as well. MSSQL also have full text search.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles