Subquery returns more than 1 row in mysql

后端 未结 3 1173
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-25 00:30

I am executing the following query and got the error \"Subquery returns more than 1 row\"

My Query is

SELECT pkTicketID,
       TicketReplyDateAdded,
           


        
相关标签:
3条回答
  • 2021-01-25 00:41

    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.

    0 讨论(0)
  • 2021-01-25 00:47

    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.

    0 讨论(0)
  • 2021-01-25 01:05

    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')

    0 讨论(0)
提交回复
热议问题