I am writing a nested MySQL query where a subquery returns more than one row and hence the query can not be executed.
Can anyone suggest me a solution for this problem?
Thanks in advance.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
An error about a subquery returning more than one value says to me that you’re attempting a straight value comparison, like this:
The solution depends on the data coming from the subquery – do you want the query to use all the values being returned? If yes, then change the equals sign for an IN:
Otherwise, you need to correct the subquery so it only ever returns one value. The MAX or MIN aggregate functions are a possibliity – they’ll return the highest or lowest value. It could just be a matter of correlating the subquery:
As Tabhaza points out, a subquery generally doesn’t return more than one column (though some databases support tuple matching), in which case you need to define a derived table/inline view and join to it.
Would’ve been nice to have more information on the issue you’re having…