表一:
SELECT
mp.MouldCode,
a.ProduceCode,
a.InsertCode
FROM
( SELECT InsertCode, ProduceCode FROM Produce_Inserts WHERE ProduceCode = '06.GA037A.A210B' AND InsertCode NOT IN ( SELECT insertcode FROM Produce_Inserts WHERE ProduceCode = '06.GA036A.C210A' ) ) a
LEFT JOIN Mould_Produces mp ON a.ProduceCode = mp.ProduceCode
表二:
SELECT
mp1.MouldCode,
a1.ProduceCode,
a1.InsertCode
FROM
( SELECT InsertCode, ProduceCode FROM Produce_Inserts WHERE ProduceCode = '06.GA036A.C210A' AND InsertCode NOT IN ( SELECT insertcode FROM Produce_Inserts WHERE ProduceCode = '06.GA037A.A210B' ) ) a1
LEFT JOIN Mould_Produces mp1 ON a1.ProduceCode = mp1.ProduceCode
我要把表二连接到表一右边,用左连接会产生笛卡尔积。请问我要怎么写?
SELECT
aa.MouldCode,
aa.ProduceCode,
aa.InsertCode,
bb.ProduceCode,
bb.InsertCode
FROM
(
SELECT
mp.MouldCode,
a.ProduceCode,
a.InsertCode
FROM
( SELECT InsertCode, ProduceCode FROM Produce_Inserts WHERE ProduceCode = '06.GA037A.A210B' AND InsertCode NOT IN ( SELECT insertcode FROM Produce_Inserts WHERE ProduceCode = '06.GA036A.C210A' ) ) a
LEFT JOIN Mould_Produces mp ON a.ProduceCode = mp.ProduceCode
) aa
LEFT JOIN (
SELECT
mp1.MouldCode,
a1.ProduceCode,
a1.InsertCode
FROM
( SELECT InsertCode, ProduceCode FROM Produce_Inserts WHERE ProduceCode = '06.GA036A.C210A' AND InsertCode NOT IN ( SELECT insertcode FROM Produce_Inserts WHERE ProduceCode = '06.GA037A.A210B' ) ) a1
LEFT JOIN Mould_Produces mp1 ON a1.ProduceCode = mp1.ProduceCode
) bb ON aa.MouldCode = bb.MouldCode