私はこのクエリーを働かせようとしていて、誰かが私に助言を与えることを望んでいます。
私は2つのテーブルを持っています。マスターとAUX。 groupidとsection idに基づいてマスターではなくAUXにある行でマスターを更新する必要があります。
私は実際に複数のAUXテーブルでこれを行う必要がありますが、私は1つの上でそれを行う方法を見つけることができる限り、私は手動で私は必要な各テーブルに対してクエリを手動で実行することができます。
これまでは、selectを使用してマスターに挿入する必要があるAUXからデータを取得しようとしていましたが、これを変更して挿入クエリを作成することができます。
select
a.id
from
master as m,
aux as a
where
a.gid = m.groupid
and
a.sid = m.sectionid
and
not in m.groupid
and
not in m.sectionid
このクエリは機能していません:(
マスターテーブル
id groupid sectionid
1 A Group 21
2 A Group 23
3 B Group 55
4 C Group 999
5 D Group 52A
6 D Group 53
AUXテーブル
id gid sid
1 A Group 21
2 A Group 22
3 A Group 23
4 B Group 55
5 B Group 55A
6 C Group 999
7 D Group 52A
8 D Group 53
9 D Group 56
クエリ後のマスタテーブル
id groupid sectionid
1 A Group 21
2 A Group 23
3 B Group 55
4 C Group 999
5 D Group 52A
6 D Group 53
7 A Group 22
8 B Group 55A
9 D Group 56
助けをありがとうございました。
回答:
回答№1は4私は思っていない and not in m.groupid
有効なSQLです。 A not exist
サブセレクトでこのトリックを行う必要があります:
insert into master (groupid, sectionid)
select a.gid, a.sid
from aux as a
where not exists(
select *
from master as m
where m.groupid = a.gid
and a.sid = m.sectionid
)
回答№2の場合は0
あなたはこれを試すことができます...
select
id
from
aux as a
where
not exists (
select
id
from
master
where
groupid = a.gid
and
sectionid = a.sectionid
)