· 8 years ago · Mar 16, 2018, 12:40 PM
1create table if not exists `example`(
2`firstNames` varchar(45) not null,
3`secondNames` varchar(45) not null)
4ENGINE = InnoDB;
5
6insert into example values('Jose Alonzo', 'Pena Palma');
7
8select * from example;
9
10| firstNames | secondNames |
11----------------------------
12| Jose Alonzo| Pena Palma |
13
14set @search = 'jose alonzo pena';
15select * from example
16where concat(firstNames, ' ', secondNames) like concat('%',@search,'%');
17
18| firstNames | secondNames |
19----------------------------
20| Jose Alonzo| Pena Palma |
21
22set @search = 'jose pena';
23select * from example
24where concat(firstNames, ' ', secondNames) like concat('%',@search,'%');
25
26| firstNames | secondNames |
27
28where concat(firstNames, ' ', secondNames) like concat('%', replace(@search, ' ', '%'), '%')