Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/65.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql 将LIKE用于2列_Mysql - Fatal编程技术网

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