开发者

SQl Query to retrieve data

开发者 https://www.devze.com 2023-03-11 22:12 出处:网络
I cannot figure out how to get the required data from my table. The query which I wrote shows an error saying subquery returns more than one row..

I cannot figure out how to get the required data from my table. The query which I wrote shows an error saying subquery returns more than one row..

SELECT name  
FROM `business`
WHERE id = (
SELECT business_id
FROM bill 
WHERE id = (
SELECT bill_id
FROM bill_schedule
WHERE show_bill = 1 )

Here the subquery for bill_schedule returns more than one row, where show_bill is a boolean column. All I want here is to display the 'name' from the business whose show_bill 开发者_StackOverflow中文版is set to 1.


SELECT `name`  
FROM `business`
WHERE id in (
SELECT business_id
FROM bill 
WHERE id in (
SELECT bill_id
FROM bill_schedule
WHERE show_bill = 1 )


Since the sub query is returning multiple rows, you can't use an equality operator

Just change the = to IN in your where clause:

SELECT name  
FROM `business`
WHERE id IN (
SELECT business_id
FROM bill 
WHERE id IN (
SELECT bill_id
FROM bill_schedule
WHERE show_bill = 1 )
0

精彩评论

暂无评论...
验证码 换一张
取 消