需要连接两个 tables,其中 table A 中所有数据都是正确的
Need to join two tables where all data is correct in table A
我有两个 table 格式相同。它们看起来像这样:
tableA中的所有数据都是正确的。它包含 158.000 个 EAN 号码。在 table B 中大约有 5.000 个 EAN 号码。 table B 中有一些 EAN 编号,但是 table A 中没有。我需要制作一个新的 table,其中包含来自 table A + EAN 的所有数据table B 中的数字不在 table A.
中
起初我做了一个union,然后又做了一个union all。这就是我发现存在重复值的方式。 Table B 仅包含 MeterNumberOfDigits、MeterConversionFactor 和 MeterUnitType 的 NULL 值。我不知道如何正确进行连接,以便保留这些行中的信息。
select EAN from A union select EAN from B.
union all 会保留重复值,union 只保留
独特的价值。
如果你这样做
select * from A union select * from B
相同的 EAN 行并不意味着同一行,它们在其他列上可能不同
希望对您有所帮助
以下查询将为您提供 table A
中的所有记录和 tableB
中包含 table A
中未找到的 EANno
的记录:
select [Your column list] from tableA A
inner join tableB B
on A.EANno = B.EANno
union all
select [Your column list] from tableB B
where B.EANno not in (select distinct EANno from tableA)
我有两个 table 格式相同。它们看起来像这样:
tableA中的所有数据都是正确的。它包含 158.000 个 EAN 号码。在 table B 中大约有 5.000 个 EAN 号码。 table B 中有一些 EAN 编号,但是 table A 中没有。我需要制作一个新的 table,其中包含来自 table A + EAN 的所有数据table B 中的数字不在 table A.
中起初我做了一个union,然后又做了一个union all。这就是我发现存在重复值的方式。 Table B 仅包含 MeterNumberOfDigits、MeterConversionFactor 和 MeterUnitType 的 NULL 值。我不知道如何正确进行连接,以便保留这些行中的信息。
select EAN from A union select EAN from B.
union all 会保留重复值,union 只保留 独特的价值。
如果你这样做
select * from A union select * from B
相同的 EAN 行并不意味着同一行,它们在其他列上可能不同
希望对您有所帮助
以下查询将为您提供 table A
中的所有记录和 tableB
中包含 table A
中未找到的 EANno
的记录:
select [Your column list] from tableA A
inner join tableB B
on A.EANno = B.EANno
union all
select [Your column list] from tableB B
where B.EANno not in (select distinct EANno from tableA)