我有桌子Member
和Transaction
. 表Member
有 2 列MemberID
和MemberName
. 表Transaction
有 3 列,MemberID
、TransactionDate
和MemberBalance
。
表中的行如下所示:
表Member
:
MemberID MemberName
=============================
1 John
2 Betty
3 Lisa
表Transaction
:
MemberID TransactionDate MemberBalance
=====================================================
1 13-12-2012 200
2 12-12-2012 90
1 10-09-2012 300
我想MemberID, MemberName
查询MemberBalance
每个.TransactionDate
MemberID
我的查询是这样的:
SELECT
t.MemberID, m.MemberName , t.MemberBalance
FROM
Member AS m
INNER JOIN
Transaction AS t ON m.MemberID = t.MemberID
WHERE
t.TransactionDate IN (SELECT MAX(TransactionDate)
FROM Transaction
GROUP BY MemberID)
此查询返回:
MemberID MemberName MemberBalance
===================================================
1 John 200
2 Betty 90
我的问题是,我希望查询返回:
MemberID MemberName MemberBalance
===================================================
1 John 200
2 Betty 90
3 Lisa NULL
即使该成员在表格MemberID
中不存在,我也希望显示该成员。Transaction
我该怎么做呢?
谢谢你。