Mysql 将LIKE用于2列
我需要在Mysql 将LIKE用于2列,mysql,Mysql,我需要在hostel表中搜索 结构: CREATE TABLE hostel( p_id VARCHAR(5) NOT NULL, hostel VARCHAR(50) NOT NULL, address VARCHAR(50) NOT NULL PRIMARY KEY(p_id)); 我已在$word select * from hostel where hostel like '%$word%' 下面的查询是否有效?我需要在“招待所”和“地址”栏中搜索 这是没有问题的 会带来更好的结果
hostel
表中搜索
结构:
CREATE TABLE hostel(
p_id VARCHAR(5) NOT NULL,
hostel VARCHAR(50) NOT NULL,
address VARCHAR(50) NOT NULL
PRIMARY KEY(p_id));
我已在$word
select * from hostel where hostel like '%$word%'
下面的查询是否有效?我需要在“招待所”和“地址”栏中搜索
这是没有问题的
会带来更好的结果为什么不直接测试一下呢?这取决于你想要什么。您的查询将只生成hotels,其中hotel和address包含文本$word。我认为您需要将AND更改为OR,这样当hotel或address包含$word时,它将返回行。
Better change those searchable fields(hostel,address) to full text which will fasten the search
SELECT MATCH('Content') AGAINST ('keyword1
keyword2') as Relevance FROM table
select match($word) against (hostel,address) as Relevance FROM table
select * from hostel where hostel like '%$word%' AND address like '%$word%'
select * from hostel where hostel like '%$word%' OR address like '%$word%'
Better change those searchable fields(hostel,address) to full text which will fasten the search
SELECT MATCH('Content') AGAINST ('keyword1
keyword2') as Relevance FROM table
select match($word) against (hostel,address) as Relevance FROM table