Subquery returns more than 1 row in mysql

为君一笑 提交于 2019-12-02 05:53:50

You can fix this error by limiting the subquery to return only one row, like this:

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
        LIMIT 1) = 7 
AND     T.TicketStatus = 'Replied' 
ORDER   BY pkTicketReplyID DESC

(Added 'LIMIT 1')

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.

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!