Red Bridge Internet is a San Francisco WordPress Consulting firm specializing in WordPress websites and WordPress Plugin Development. We're the ones you have been searching for.

MySQL Search Across Columns with Concat

Using MySQL’s Concat and Concat_Ws is your friend when trying to search two joined column/field values.

This will sometimes be encountered in a simple example such as a name search, when you have two columns: 1. First Name (fname) and 2. Last Name (lname) and your search criteria is by Full Name.

So, let’s say you have a table named ‘gms’ with 2 columns, first name and last name:

fname  lname
billy beane
brian  cashman

Let’s say, you’re searching for a great general manager. You would of course search for the full name;  “billy beane”.

The sql for this would look like so:

select * from gms where concat_ws(‘ ‘,fname,lname) like “%billie beane%”;

You can also just strip the space and use ‘concat’:

select * from gms where concat(fname,lname) like “%billiebeane%”;

So, that’s about it. Using MySQL concat to search the value of 2 joined columns.

Incoming search terms:

  • mysql concat
  • mysql WHERE concat
  • mysql concat where
  • mysql search concat
  • mysql concat search
  • concat mysql
  • mysql like two columns
  • mysql like concat
  • mysql concat columns
  • WHERE CONCAT Mysql

Related posts:

  1. Working with MySQL SET Data Type
  2. How to Check MySQL Version on Command Line
  3. Search with Find, Xargs, and Grep
  4. A MySQL Sub Select Wish

4 responses to “MySQL Search Across Columns with Concat”

  1. Daniel

    Thanks!, just what I was looking for

  2. kiran

    thanks a lot for this tip. Really kool.

  3. adrian

    Hello, I have tried searching multiple columns with this technique only on 3 joined tables. The problem is that when I join a fourth table the results for the same search terms aren’t the same anymore. Any help is appreciated thanks.

  4. jhonyia

    query is not working its giving error

Leave a Reply