简体   繁体   English

SQl 查询检索数据

[英]SQl Query to retrieve data

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.这里 bill_schedule 的子查询返回多行,其中 show_bill 是 boolean 列。 All I want here is to display the 'name' from the business whose show_bill is set to 1.我在这里只想显示 show_bill 设置为 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:只需在 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 )

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM