Jump to content

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


Jakez

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%';

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.