2016-05-29 12 views
-2

こんにちは私は3つのテーブルを持っている私は3つのテーブルから同じ列を抽出したい選択クエリを書くためにこのより良い方法です。3つの異なるテーブルから同じ列を抽出するSQL

select * from 
(
select col1, 
select id1 from testid1 where name=pnrtable1.name, 
col3 from table1 
union all 
select coltab1, 
select newid2 from testid2 where name=pnrtable2.name, 
coltab3 from table2 
union all 
select namecol1, 
select id3 from testid3 where name=pnrtable3.name, 
namecol3 from table3 
) 
+0

あなたのクエリでは、あなたの構文が間違っています。 –

+0

あなたは 'MySQL'または' SQL Server'を使用していますか? – Squirrel

+0

私はNetezzaを使用しています – Sai

答えて

1
わから

ないが、私はあなたがこのようなものの後にあると思います....それも解析できないでしょうであるよう

select * from 
(
select t1.col1, t2.id1 , t1.col3 from table1 t1 
           INNER JOIN testid1 t2 ON t1.name = t2.name 
union all 
select t1.coltab1, t2.newid2, t1.coltab3 from testid2 t1 
             INNER JOIN table2 t2 ON t1.name=t2.name 
union all 
select t1.namecol1, t2.id3, t1.namecol3 from testid3 t1 
             INNER JOIN table3 t2 ON t1.name=t2.name 
) A