Subquery Returns more than 1 Row Mysql

Asked

Viewed 375 times

1

Follow the code below that is causing the error quoted in the title:

select (select id from message where user_from = tempMsg.user OR user_to = tempMsg.user) as id from tempMsg

How can I fix it? Someone could help me fast?

  • What exactly do you want to get there? Want to query tempMsg a caught message id?

1 answer

0

Instead of this understatement try this:

select a.id
from message a 
inner join tempMsg b
on a.user_from = b.user
and a.user_to = b.user
  • I believe that the ON clause should be OR in place of AND, otherwise it will only pick up messages sent by a user to itself.

  • Consider adding comparative explanations about his code and his code to facilitate understanding of your solution.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.