sql 搜索查询仍未产生预期结果
我需要计数和搜索查询才能正常工作。计数查询似乎工作正常,但搜索查询却无法正常工作。
计数查询:
SELECT COUNT(DISTINCT tg_id)
FROM tg_keywords
WHERE tg_keyword LIKE 'keyword_1' OR tg_keyword LIKE 'keyword_2'
ORDER BY tg_keyword LIKE 'keyword_1' AND tg_keyword LIKE 'keyword_2 DESC
Returns 1 count as expected.
搜索查询:
SELECT DISTINCT tg_keywords.tg_id
FROM tg_keywords LEFT JOIN tg_info.tg_id=tg_keywords.tg_id
WHERE tg_keyword LIKE 'keyword_1' OR tg_keyword LIKE 'keyword_2'
ORDER BY tg_keyword LIKE 'keyword_1' AND tg_keyword LIKE 'keyword_2' DESC, tg_info.date_added LIMIT 16 OFFSET 1
Returns 0 results (1 is expected)
如有任何建议,我们将不胜感激
提前致谢, 阿奇
I need a count and search query to work properly. The count query appears to be working properly, however the search query is not.
Count query:
SELECT COUNT(DISTINCT tg_id)
FROM tg_keywords
WHERE tg_keyword LIKE 'keyword_1' OR tg_keyword LIKE 'keyword_2'
ORDER BY tg_keyword LIKE 'keyword_1' AND tg_keyword LIKE 'keyword_2 DESC
Returns 1 count as expected.
Search query:
SELECT DISTINCT tg_keywords.tg_id
FROM tg_keywords LEFT JOIN tg_info.tg_id=tg_keywords.tg_id
WHERE tg_keyword LIKE 'keyword_1' OR tg_keyword LIKE 'keyword_2'
ORDER BY tg_keyword LIKE 'keyword_1' AND tg_keyword LIKE 'keyword_2' DESC, tg_info.date_added LIMIT 16 OFFSET 1
Returns 0 results (1 is expected)
Any advice would be greatly appreciated
Thanks in advance,
Archie
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
删除查询末尾的
OFFSET 1
,然后尝试。OFFSET 1
告诉它为您提供第二行中的记录。要么将其设为OFFSET 0
,要么将其完全删除。Remove the
OFFSET 1
at the end of the query and then try it.The
OFFSET 1
tells it to give you records from the SECOND row. Either make itOFFSET 0
or remove it altogether.ORDER BY 部分是怎么回事?你的意思:
What's with that ORDER BY part? Did you mean:
您还想赋予用户使用 SQL 通配符的能力吗?如果不是,我可能会放弃 like 并放入 =。
Also do you want to give the user the ability to use SQL wildcards? If not I probably ditch like and put in an =.