Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL combine columns before matching it with LIKE

I have two columns in my database that I want to combine before matching them using LIKE statement.

My table:

|---------------------------------|
|   ID     |   PREFIX  |  SUFFIX  |
|---------------------------------|
|   1      |     31    |   523    |
|---------------------------------|
|   2      |     62    |   364    |
|---------------------------------|

I want to be able to supply 315 and ID 1 would be returned. Is there any easy way of doing it? At the moment I am splitting search string and matching separate columns.

Thanks.

like image 495
Shepard Avatar asked Sep 22 '15 14:09

Shepard


1 Answers

SELECT * FROM table WHERE CONCAT(PREFIX, SUFFIX) LIKE '%315%'
like image 170
pierroz Avatar answered Oct 02 '22 23:10

pierroz