【问题标题】:how to show these results in one line in oracle如何在 oracle 的一行中显示这些结果
【发布时间】:2013-07-10 03:03:07
【问题描述】:

目前我有这三个表,结构非常相似

table1:id1 name1
table2:id2 name2
table3:id3 name3

我想要的结果是

name1  name2   name3
value1 value2  value3

我尝试使用union,sql是:

select name1 from table1 where id1 = '1' 
union select name2 from table2 where id2 = '2' 
union select name3 from table3 where id3 = '3'

但结果却是:

name1     
value1
value2
value3

【问题讨论】:

  • 您是要准确地id1=1id2=2id3=3中选择,还是要结合一些规则?
  • 1,2,3 将是来自用户输入的参数
  • 你的问题还没解决吗?

标签: sql oracle


【解决方案1】:
SELECT
  (select name1 from table1 where id1 = '1'),
  (select name2 from table2 where id2 = '2'),
  (select name3 from table3 where id3 = '3')
from dual;

【讨论】:

    【解决方案2】:
    select name1,name2,name3 from table1,table2,table3
    where table1.id1=1 and table2.id2=2 and table3.id3=3;
    

    fiddle

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-07-23
    • 2018-07-14
    • 2017-02-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多