以下查询返回
“单行子查询返回多行”
select * from sampleTable
where
status = 'A'
and (SELECT SUBSTR(some_code_column, 1, 4) from sampleTable) = 9999
我需要获取状态为A的表的所有行以及SUBSTR(some_code_column, 1, 4) = 9999
的所有行
如何更改查询以便获取所需的结果?
答案 0 :(得分:2)
这是在您澄清之前,您想要返回满足两个条件而不是一个或另一个的数据。
我会在这种情况下使用UNION
。
SELECT *
FROM sampleTable
WHERE status = 'A'
UNION
SELECT *
FROM sampleTable
WHERE SUBSTR(some_code_column, 1, 4) = 9999
答案 1 :(得分:1)
不需要那个子选择,只需和条件:
select * from sampleTable
where
status = 'A'
and SUBSTR(some_code_column, 1, 4) = 9999
答案 2 :(得分:0)
你想要两个条件成真或其中任何一个?如果是其中任何一个,请使用BkgView extends View
代替OR