大型 MySql 查询出错
我正在尝试使用以下 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您不需要第二个
WHERE
关键字。 您可以在OR
中包含两件事:例如,
You don't need the second
WHERE
keyword. You can have 2 things in anOR
like thisfor instance: