Jump to content

How come this LIKE clause isn't working to search words?


Recommended Posts

OK I have a search form on my page, I want to search the database for each word someone types in, for example instead of matching the exact phrase "song lyrics" I want it to search for fields containing "song" AND/OR "lyrics".

 

I tried this query below but no luck:

 

SELECT * FROM table WHERE field LIKE 'song' OR field LIKE 'lyrics' OR other_field LIKE 'song' OR other_field LIKE 'lyrics'

 

What am I doing wrong?

SELECT *
FROM table
WHERE field IN ('song', 'lyrics')
     OR other_field IN ('song', 'lyrics');

 

 

 

Uh....  You either didn't read his question or you don't know what IN does.

 

 

 

 

With LIKE you have to use certain symbols.  ? means 1 of any character, and % means any amount of any character...

 

 

So you could do something like:

 

 

SELECT * FROM blah WHERE field LIKE '%someword%';

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.