我正在尝试更高效、优雅地实现这个目标。
SELECT
MD.*,
(SELECT City FROM PostcodeData WHERE MD.Postcode = Postcode) [City],
(SELECT State FROM PostcodeData WHERE MD.Postcode = Postcode) [State],
(SELECT Areacode FROM PostcodeData WHERE MD.Postcode = Postcode) [Areacode]
FROM MemberDetails AS MD
我可以很明显地使用INNER JOIN在Postcode上连接这两个表,但是当MemberDetail.postcode不存在于PostcodeData.postcode中时,我会遇到问题。在这种情况下,我仍然希望选择这些成员,但是City、State和Areacode的结果为NULL。目前的查询实现了这一点,但效率非常低。如果有任何想法,将不胜感激。谢谢!