-1

我需要在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”和“address”列中搜索

select * from hostel where hostel like '%$word%' AND address like '%$word%'
4

3 回答 3

2
select * from hostel where hostel like '%$word%' OR address like '%$word%'

会带来更好的结果

于 2012-12-14T10:45:52.913 回答
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 
于 2012-12-14T11:33:23.010 回答
0

这没有问题

select * from hostel where hostel like '%$word%' AND address like '%$word%'
于 2012-12-14T10:45:22.403 回答