Mysql - 简单的选择查询返回重复值?

发布于 2024-09-24 08:35:52 字数 273 浏览 2 评论 0原文

查询如下所示:(简化)

SELECT * FROM posts WHERE user='37' ORDER BY date DESC

我当前在该表中仅保存一行,但由于某种原因它仍然返回完全相同的两行。起初我以为我搞砸了循环,但我尝试用 print_r() 打印返回的数组,它实际上返回两行。

我尝试搜索,但没有发现任何类似的问题。不过,我确实记得我的一个朋友在学校也遇到了同样的问题,所以我确信我们不是唯一的。我可能只是没有使用正确的搜索词,呵呵。

This is how the query looks like: (simplified)

SELECT * FROM posts WHERE user='37' ORDER BY date DESC

I currently only ave one row in that table, but still for some reason it returns two rows that are exactly the same. At first i thought i messed up with the loop, but i tried printing the returned array out with print_r() and it actually returns two rows.

I tried searching, but i didn't find any similar issues. I do however remember that a friend of mine had the same issue at school, so i'm sure we aint the only ones. I probably just didn't use the right search terms, heh.

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

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

发布评论

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

评论(3

娇纵 2024-10-01 08:35:52

如果您只有一条记录(验证这一点),则必须是应用程序逻辑复制返回值。

If you have only one record (verify this), it has to be application logic that is duplicating the returned values.

天暗了我发光 2024-10-01 08:35:52

确定表格中只有一行吗?如果是这样,那么问题似乎一定发生在 SQL 之外。

除了这个查询之外你还在做什么?这似乎是问题的可能根源。您提到了一个循环:您可以将查询结果添加到数组中两次吗?或者数组是否在调用之间保持不变而没有重新初始化(换句话说,先前查询的结果在您不希望的情况下保留在数组中)?

Are you sure you only have one row in the table? If so, it seems like the problem must be happening outside of SQL.

What are you doing outside of this query? That seems like the likely source of the issue. You mention a loop: could you be adding the query result to your array twice? Or is the array persisting between calls without being reinitialized (in other words, the result of a previous query is remaining in the array when you don't expect it to)?

日裸衫吸 2024-10-01 08:35:52

limit 1 是你的朋友:)

尝试将其添加到查询的末尾。

limit 1 is your friend :)

Try adding it to the end of your query.

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