sql 搜索查询仍未产生预期结果

发布于 2024-09-18 14:09:21 字数 699 浏览 8 评论 0原文

我需要计数和搜索查询才能正常工作。计数查询似乎工作正常,但搜索查询却无法正常工作。

计数查询:

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 技术交流群。

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

发布评论

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

评论(3

疯到世界奔溃 2024-09-25 14:09:22

删除查询末尾的 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 it OFFSET 0 or remove it altogether.

古镇旧梦 2024-09-25 14:09:22
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

ORDER BY 部分是怎么回事?你的意思:

WHERE tg_keyword LIKE 'keyword_1' OR tg_keyword LIKE 'keyword_2' 
ORDER BY tg_info.date_added DESC
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

What's with that ORDER BY part? Did you mean:

WHERE tg_keyword LIKE 'keyword_1' OR tg_keyword LIKE 'keyword_2' 
ORDER BY tg_info.date_added DESC
少女情怀诗 2024-09-25 14:09:22

您还想赋予用户使用 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 =.

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