大型 MySql 查询出错

发布于 2024-11-18 09:33:49 字数 649 浏览 0 评论 0原文

我正在尝试使用以下 MySql 查询,但是它在第 3 行的“WHERE FIND_IN_SET('query', Alternate_name)”处返回语法错误。我尝试用谷歌搜索它并查看 MySql 手册,但是我不能似乎找到了如何修复它。

查询:

SELECT name, 'Events' as source FROM feed_events WHERE name LIKE '".$query."%' UNION ALL    
SELECT name, 'Venues' as source FROM feed_venues WHERE name LIKE '".$query."%' UNION ALL
SELECT name, 'Locations' as source FROM feed_locations WHERE name LIKE '".$query."%' OR WHERE FIND_IN_SET('".$query."', Alternate_name)

在有问题的 select 语句中,我尝试选择最适合用户输入的字符串($query)的城市名称。第一列是城市名称,第二列中有一个以逗号分隔的该城市的备用名称列表。 find_in_set() 应该搜索该列中的项目以找到最佳匹配。有没有办法修复此语法错误,或者 find_in_set() 不是我想要做的事情的理想选择?

I am trying to use the following MySql query, however it returns a syntax error at 'WHERE FIND_IN_SET('query', Alternate_name)' at line 3. I've tried googling it and looking through the MySql manual, however I can't seem to find how to fix it.

Query:

SELECT name, 'Events' as source FROM feed_events WHERE name LIKE '".$query."%' UNION ALL    
SELECT name, 'Venues' as source FROM feed_venues WHERE name LIKE '".$query."%' UNION ALL
SELECT name, 'Locations' as source FROM feed_locations WHERE name LIKE '".$query."%' OR WHERE FIND_IN_SET('".$query."', Alternate_name)

In the select statement which is having the problem, I am trying to select the names of cities that best fit the string the user has inputted ($query). In the first column is the city name and in the second column I have a comma separated list of alternative names for that city. The find_in_set() is supposed to search the items in that column to find a best match. Is there a way to fix this syntax error, or is find_in_set() not the ideal choice for what I am trying to do?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

萝莉病 2024-11-25 09:33:49

您不需要第二个 WHERE 关键字。 您可以在 OR 中包含两件事:

WHERE expression1 OR expression2

例如,

WHERE field = '1' OR field = '2'

You don't need the second WHERE keyword. You can have 2 things in an OR like this

WHERE expression1 OR expression2

for instance:

WHERE field = '1' OR field = '2'
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文