gpt4 book ai didi

php - 在mysql中将两列合并为一列

转载 作者:可可西里 更新时间:2023-11-01 07:46:46 25 4
gpt4 key购买 nike

假设我有一个包含列的表:

`id`,`firstname`,`lastname`

有些行是这样的:

'1','bob','marley'
'2','mary','jane'

我有一个类似这样的搜索查询(其中“bob marley”是我的搜索词):

select * where
(`firstname` like 'bob marley%')
or
(`lastname` like 'bob marley%')

但只有当我搜索“bob”或“marley”而不是“bob marley”时,这才会成功如何连接两列以匹配搜索词?

编辑:该表将有数十万行,因此性能至关重要。 concat() 是否足够有效以在具有延迟击键调用的 ajax 搜索中工作?还是我应该重新设计我的表格或添加全文搜索列?

最佳答案

使用 MySQL 的 CONCAT功能:

SELECT * FROM tablename WHERE CONCAT(firstname, ' ', lastname) LIKE 'bob marley%'

关于php - 在mysql中将两列合并为一列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5335723/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com