0

currently i have these three table, the structures are very similar

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

my desired results will be

name1  name2   name3
value1 value2  value3

I try to use union, the sql is:

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

but the result turns out to be:

name1     
value1
value2
value3
shellter
  • 36,525
  • 7
  • 83
  • 90
jbiao
  • 1
  • 1

2 Answers2

0
SELECT
  (select name1 from table1 where id1 = '1'),
  (select name2 from table2 where id2 = '2'),
  (select name3 from table3 where id3 = '3')
from dual;
0
select name1,name2,name3 from table1,table2,table3
where table1.id1=1 and table2.id2=2 and table3.id3=3;

fiddle

Praveen Prasannan
  • 7,093
  • 10
  • 50
  • 70