Error: Subquery Returns more than 1 Row MYSQL

Asked

Viewed 110 times

-1

The column I’m adding to subquery has more than one record, but do not know how to solve:

 select productid,pb.pricebookid,(select bookname from vtiger_pricebook p 
   inner join vtiger_pricebookproductrel pbp
    on p.pricebookid = pbp.pricebookid
    where pbp.pricebookid = '299182') Wx
    from vtiger_pricebookproductrel pbp
    join vtiger_pricebook pb
    ON pb.pricebookid = pbp.pricebookid

Putting a limit of 1, it returns a repeat result because I used limit 1 just to see if it would return. Other than that it says that there is an error because I have more than one record in my subquery:

inserir a descrição da imagem aqui

I want you to come back:

inserir a descrição da imagem aqui

But I can’t get it all back because mine subquery returns more than one record.

How do I get my subquery to return more than one record?

  • Without knowing the structure of your bank is difficult.

  • I’ll edit it to make it clearer

  • 1

    Why use subquery in such a case instead of a JOIN? It is important to [Edit] and reduce the problem to a [mcve], and give an example of what the dataset is like, what you want and how the result should be

1 answer

1

So, guys, to get it I had to use wheren in in case, my consultation is so:

select productid,pb.pricebookid, listprice
from vtiger_pricebookproductrel pbp
join vtiger_pricebook pb
ON pb.pricebookid = pbp.pricebookid
where pb.bookname in (select listprice from vtiger_pricebook p inner join vtiger_pricebookproductrel pbp
on p.pricebookid = pbp.pricebookid
where pbp.pricebookid = '299182') 

WHERE pb.bookname IN then I placed my subquery and it worked!

Browser other questions tagged

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