Mysql - 简单的选择查询返回重复值?
查询如下所示:(简化)
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您只有一条记录(验证这一点),则必须是应用程序逻辑复制返回值。
If you have only one record (verify this), it has to be application logic that is duplicating the returned values.
您确定表格中只有一行吗?如果是这样,那么问题似乎一定发生在 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)?
limit 1
是你的朋友:)尝试将其添加到查询的末尾。
limit 1
is your friend :)Try adding it to the end of your query.