-1
我需要你的帮助。想我也下假表 从两个不同的表中选择
,另一个假表
我想什么是拿出了下表
select b.Country, b.AnotherCode, a.Code from Country1 a, Country2 b where a.Country=b.Country
(主关键是国家)但它不显示最后两行。如何做,以便它将检索最后一个表中显示的所有行。由于inadvance
我需要你的帮助。想我也下假表 从两个不同的表中选择
,另一个假表
我想什么是拿出了下表
select b.Country, b.AnotherCode, a.Code from Country1 a, Country2 b where a.Country=b.Country
(主关键是国家)但它不显示最后两行。如何做,以便它将检索最后一个表中显示的所有行。由于inadvance
select b.Country, b.AnotherCode, a.Code from Country1 a left join Country2 b on a.Country=b.Country
使用左连接
你返回两个集合的交集 - 如果你想要的所有行任一组,你可以使用完整的联接:
SELECT COALESCE(a.Country, b.Country) AS Country,
COALESCE(b.AnotherCode, 0) AS AnotherCode,
COALESCE(a.Code, 0) AS Code
FROM Country1 a
FULL JOIN Country2 b
ON a.Country = b.Country
当然,如果您只需要Country1
的记录和Country2
的任何对应值,那么LEFT JOIN
就足够了。同样,如果您在加入失败时想要一个不同的默认值,请更改COALESCE