0
我創建該表:mysql的像不CONCAT colums發現 '%搜索%'
create table if not exists `example`(
`firstNames` varchar(45) not null,
`secondNames` varchar(45) not null)
ENGINE = InnoDB;
現在我插入一行:
insert into example values('Jose Alonzo', 'Pena Palma');
,並檢查是否正確
select * from example;
| firstNames | secondNames |
----------------------------
| Jose Alonzo| Pena Palma |
好吧! 易 現在我創建一個statment搜索該行
set @search = 'jose alonzo pena';
select * from example
where concat(firstNames, ' ', secondNames) like concat('%',@search,'%');
這回
| firstNames | secondNames |
----------------------------
| Jose Alonzo| Pena Palma |
現在我改變 '喬斯·佩納'
set @search = 'jose pena';
select * from example
where concat(firstNames, ' ', secondNames) like concat('%',@search,'%');
值@search也不要什麼都不返回
| firstNames | secondNames |
發生了什麼事? 我不能使用像varchar中間的字符嗎?
謝謝! 這正是我想要的。 – joepa37 2014-11-23 03:16:24