子查询在mysql中返回多于1行
我正在执行以下查询并收到错误“子查询返回超过 1 行”
我的查询是
SELECT pkTicketID,
TicketReplyDateAdded,
TIMESTAMPDIFF(DAY, TicketReplyDateAdded, now()) as NumberOfDays
FROM tickets as T
LEFT JOIN ticket_replies as TR ON T.fkTicketReplyID=TR.pkTicketReplyID
WHERE 1 AND T.fkEmployeeID = '4'
AND (SELECT TIMESTAMPDIFF(DAY, TicketReplyDateAdded, now()) as NumberOfDays
FROM tickets as T
LEFT JOIN ticket_replies as TR
ON T.fkTicketReplyID=TR.pkTicketReplyID
) = 7
AND T.TicketStatus = 'Replied'
ORDER BY pkTicketReplyID DESC
感谢您的帮助。 欧麦尔
I am executing the following query and got the error "Subquery returns more than 1 row"
My Query is
SELECT pkTicketID,
TicketReplyDateAdded,
TIMESTAMPDIFF(DAY, TicketReplyDateAdded, now()) as NumberOfDays
FROM tickets as T
LEFT JOIN ticket_replies as TR ON T.fkTicketReplyID=TR.pkTicketReplyID
WHERE 1 AND T.fkEmployeeID = '4'
AND (SELECT TIMESTAMPDIFF(DAY, TicketReplyDateAdded, now()) as NumberOfDays
FROM tickets as T
LEFT JOIN ticket_replies as TR
ON T.fkTicketReplyID=TR.pkTicketReplyID
) = 7
AND T.TicketStatus = 'Replied'
ORDER BY pkTicketReplyID DESC
Thanks for your help.
Umar
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以通过限制子查询仅返回一行来修复此错误,如下所示:(
添加了“LIMIT 1”)
You can fix this error by limiting the subquery to return only one row, like this:
(Added 'LIMIT 1')
好吧,发生这种情况是因为您的子查询返回了不止一行
zerkms 来救援
ps:右侧“相关”栏中确实有很多类似的问题。
Well, this happens because your subquery returns more than one row
zerkms to the rescue
ps: it is really A LOT of similar questions in the right "related" bar.
一种方法是将
LIMIT 1
添加到子查询中。另一种方法是确定子查询在逻辑上是否应该能够返回多于一行,如果不能,则修复它。One approach is to add
LIMIT 1
to your subquery. Another is to figure out if your subquery should logically be able to return more than one row and, if not, to fix it.