SQL内连接vs LIKE不返回行

时间:2014-05-22 22:00:40

标签: mysql inner-join sql-like

那里有人可以解释为什么我的查询不起作用吗?

SELECT country.Country, city.City, location.Adress, museuminfo.Phone, museuminfo.Mail, museuminfo.Homepage, museum.MuseumName, museum.Description, museum.Collections, photo.PhotoRef 
FROM country 
INNER JOIN city 
ON country.CountryCode=city.CountryCode 
INNER JOIN location 
ON city.CityId = location.CityId 
INNER JOIN museuminfo 
ON location.LocationId = museuminfo.LocationId 
INNER JOIN museum 
ON museuminfo.MuseumInfoId = museum.MuseumInfoId 
INNER JOIN photo 
ON museuminfo.MuseumInfoId = photo.MuseumInfoId 
WHERE 
(MuseumName LIKE '%classic%') 
OR (Description LIKE '%classic%') 
OR (Collections LIKE '%classic%')
AND museum.LanguageCode = 'EN'

我有一个缩短的版本,工作正常,但你一次只能搜索一个表:

SELECT * FROM museum 
WHERE (MuseumName LIKE '%classic%') 
OR (Description LIKE '%classic%') 
OR (Collections LIKE '%classic%') 
AND museum.LanguageCode = 'EN'

请帮帮我: - (

1 个答案:

答案 0 :(得分:0)

不是绝对肯定,除非您提供一些示例数据并让我们知道查询实际尝试的内容......但请尝试更改WHERE条件,如下所示

WHERE 
(museum.MuseumName LIKE '%classic%' 
OR museum.Description LIKE '%classic%'
OR museum.Collections LIKE '%classic%')
AND museum.LanguageCode = 'EN'

(OR)

WHERE museum.LanguageCode = 'EN'
AND 
(museum.MuseumName LIKE '%classic%' 
OR museum.Description LIKE '%classic%'
OR museum.Collections LIKE '%classic%')