我无法弄清楚如何从我的表中获取所需的数据。我写的查询显示一个错误,说子查询返回多行..
SELECT name
FROM `business`
WHERE id = (
SELECT business_id
FROM bill
WHERE id = (
SELECT bill_id
FROM bill_schedule
WHERE show_bill = 1 )
这里bill_schedule的子查询返回多行,其中show_bill是一个布尔列。我想要的只是显示show_bill设置为1的商家的“名称”。
答案 0 :(得分:0)
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 )
答案 1 :(得分:0)
由于子查询返回多行,因此不能使用相等运算符
只需在where子句中将=更改为IN:
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 )