我需要在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%'
以下查询是否有效?我需要在“宿舍”和“地址”栏中搜索
select * from hostel where hostel like '%$word%' AND address like '%$word%'
答案 0 :(得分:2)
select * from hostel where hostel like '%$word%' OR address like '%$word%'
将带来更好的结果
答案 1 :(得分:2)
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
答案 2 :(得分:0)
这没有问题
select * from hostel where hostel like '%$word%' AND address like '%$word%'