Error in DB query: “Unable to save result set”

Have a request

 "SELECT datacenter.id, text, 
  (SELECT avatar FROM massage WHERE id_finish= '$id')
  AS finishavatar, id_finish, datacenter.name, datacenter.surname 
  FROM massage JOIN datacenter 
  ON datacenter.id = massage.id_finish WHERE  massage.id_start= '$id'"

It throws an error

Warning: mysql_query() [function.mysql-query]: Unable to save result set in Y:\home\localhost\www\u\massage_my.php on line 52
Subquery returns more than 1 row


Answer 1, authority 100%

So such a question is not physically possible, judging by what I see you have duplicate id_finish (i.e. id_finish is not unique), and this is a prerequisite for such a request.

Actually, in your sub-request


SELECT avatar FROM massage WHERE id_finish= '$id'

More than one value is returned, which is why an error occurs if you have the time of the message stored in the database. Of course, you can, so that there is no error, write something like


SELECT datacenter.id, text, 
   (SELECT avatar FROM massage WHERE id_finish= '$id' ORDER BY id DESC LIMIT 1)
      AS finishavatar, id_finish, datacenter.name, datacenter.surname 
           FROM massage JOIN datacenter 
                ON datacenter.id = massage.id_finish WHERE  massage.id_start= '$id'

But this request will not bring expectedresults, you need to think about how to implement the connection. and it is better to change structures of your database in general. To summarize briefly – in your case, it is impossible to make the request you want due to lack of communication


Answer 2

> fetch first 1 rows only

add at the end, it should work