Jump to content

mysql construct to apply multiple fields to a single like

Recommended Posts

Still new.  Off topic - not really php?  Hope not.  Who else knows mysql like the php crowd.


I find this clause  construct in many places on this new site:

and t2.keyword like concat('%', :bc11, '%')
 or t2.name    like concat('%', :bc12, '%')
 or t2.des     like concat('%', :bc13, '%')

He's trying to find the search term anywhere in any of the 3 fields.  bc11, bc12 and bc13 are binding 'keys' that receive identical values.  Is there a way to build this something like this:?

and any (t2.keyword, t2.name, t2.des) like concat('%', :bc11, '%')

I had to make up something my self :-).  Thanks.


Share this post

Link to post
Share on other sites

I don't you can concat substitute parms. But you can make the values behind those parms work by concatenating the % to the values you assign to those parms.

Share this post

Link to post
Share on other sites

If you are doing wildcard searches, using LIKE, you are stuck with the long version I'm afraid. Alternative is FULLTEXT index search.


(Moving to MySql forum)

Share this post

Link to post
Share on other sites

Join the conversation

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

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.