这个SQL查询语句怎么写?
这里用到两个表,一个Member,一个MemberAction
Member的字段和值如下:
ID Name
1 张三
2 李四
MemberAction的字段和值如下:
MemberFromID MemberToID Content
1 2 打招呼
我想要的结果是从表MemberAction取出三个字段的结果来,但把1显示成张三,把2显示成李四,这个语句怎么写?
谢谢!
[解决办法]
select M1.Name AS Name1,M2.Name AS Name2,Ma.Content from MemberAction Maleft join Member M1 ON M1.ID = Ma.MemberFromIDleft join Member M2 ON M2.ID = Ma.MemberToID
[解决办法]
SELECT ( select b.name from member b where a.MemberFromID = b.id ) as MemberFromID ,
( select b.name from member b where a.MemberToID = b.id ) as MemberToID ,
Content
FROM memberaction a
试试吧。