私は2つの異なるクエリを持っています(結果に同じ列数があります)。 両方を1つのテーブルに入れたい。今2つの異なるクエリ結果を1つのテーブルに追加します。
id country salary
1 us 10000
2 uk 25000
3 us 35000
4 uk 31000
5 uk 26000
私は次のようたクエリ:
クエリ1:
select * from table where country='us';
と
クエリ2:
例えば、私は次の表ている私は1つのファイナルテーブルは以下のように6つの列を持ってい
:
id1 |country1 | salary 1 | id2 | country2 | salary2
さて、私は両方のクエリを入れたいが、この表につながるので、次の出力が表示されるはずです。
所望の出力:
をid1 |country1 | salary 1 | id2 | country2 | salary2
1 | us | 10000 | 2 | uk | 25000
3 | us | 35000 | 4 | uk | 31000
null | null | null | 5 | uk | 26000
私はこれを試してみましたが、それは結果を結合していない:
insert into table (id1,country1,salary1)
select id,country,salary
from table1
where country='us';
と
insert into table (id2,country2,salary2)
select id,country,salary
from table1
where country='uk';
が、それは次のような結果得られます。
id1 |country1 | salary 1 | id2 | country2 | salary2
1 | us | 10000 | null | null | null
3 | us | 35000 | null | null | null
null | null | null | 2 | uk | 25000
null | null | null | 4 | uk | 31000
null | null | null | 5 | uk | 26000
を私を助けてください:
ではなく、2つの挿入文はどのよう –
の1つのinsert文にそれらを追加するために参加しますか?私はどのように挿入ステートメントで結合を使用するか分からない。 – Paras
あなたが使用しているDBMSのタグを追加 –