如何在1个查询中组合4个查询? (ORACLE SQL)

时间:2020-09-23 05:43:02

标签: database oracle-sqldeveloper

你好,我想进行组合查询。

从代码='?'的表中选择*;

从代码='?的表中选择*或code ='?';

从代码='?的表中选择*或代码='?'或code ='?';

从代码='?的表中选择*或代码='?'或代码='?'或code ='?';

我对此进行4查询,但我想将其合并。我怎么能?

并且代码具有4个值,例如1,2,3,4 请帮我! (我正在使用oracle 11,SQL Developer)

2 个答案:

答案 0 :(得分:1)

例如,您可以使用全部合并

select * from table where code='?';
union all
select * from table where code='?' or code='?';
union all
select * from table where code='?' or code='?' or code='?';
union all
select * from table where code='?' or code='?' or code='?' or code='?';

或者您可以像这样使用IN运算符

select * from table where code in ('?',?','?','?')

答案 1 :(得分:0)

我不确定问题的措辞方式,但我认为您可能正在寻找IN声明?

SELECT * FROM tablename WHERE code IN ('1' ,'2' ,'3' ,'4');

有关此的更多信息,请访问

https://docs.oracle.com/database/121/SQLRF/conditions014.htm

相关问题