日期:2014-05-18  浏览次数:20550 次

这个SQL查询语句怎么写?
这里用到两个表,一个Member,一个MemberAction

Member的字段和值如下:
ID Name
1 张三
2 李四

MemberAction的字段和值如下:
MemberFromID MemberToID Content
1 2 打招呼 


我想要的结果是从表MemberAction取出三个字段的结果来,但把1显示成张三,把2显示成李四,这个语句怎么写?
谢谢!

------解决方案--------------------
SQL code

select M1.Name AS Name1,M2.Name AS Name2,Ma.Content from 
MemberAction Ma
left join Member M1 ON M1.ID = Ma.MemberFromID
left 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 

试试吧。