有2张表topic(id title authorId lastReplyId) user(id name)
topic中的authorId lastReplyId 引用user表中的id,2张表不存在外键
我想查询出如下结果
id title authorname(作者) lastReplyName(最后回复人)
1 你好 张三 王五
2 我不好 李四 王五
怎么写sql语句,实在不知道咋写,求解了
SELECT
t.topicId,
t.title,
t.lastReplyId,
u.`name` AS authorname
FROM
topic t
JOIN `user` u ON t.authorId = u.id 这是我的sql语句,但是只能得到authorname
但是我还想得到lastReplyname,上面的sql咋改
topic中的authorId lastReplyId 引用user表中的id,2张表不存在外键
我想查询出如下结果
id title authorname(作者) lastReplyName(最后回复人)
1 你好 张三 王五
2 我不好 李四 王五
怎么写sql语句,实在不知道咋写,求解了
SELECT
t.topicId,
t.title,
t.lastReplyId,
u.`name` AS authorname
FROM
topic t
JOIN `user` u ON t.authorId = u.id 这是我的sql语句,但是只能得到authorname
但是我还想得到lastReplyname,上面的sql咋改
解决方案 »
- oracle替换成MySQL,c链接库proc转换的问题
- mysql event 问题
- 怎么让mysql查询的时候隔5个数据出现一次
- MYSQL问题
- MySQL5.0的MySQL query browser1.1工具中文出现乱码怎么解决?
- I have download the sourcecode of the Mysql . but I can not find the development document(I have try my best to do it )
- 求助操作ResultSet的操作
- 现在有哪家公司的数据库平台是采用mysql的???
- mysql_stmt_send_long_data 能支持update语句吗?
- 请问如何调用MYSQL的api来获取我刚刚插入的记录的主键?
- 求mysql一个修改
- 关于mysql 添加用户的问题
from topic A,user B,user C
where A.lastReplyid=B.id and A.authorid=C.id
t.topicId,
t.title,
t.lastReplyId,
u.`name` AS authorname,u1.`name` AS lastReplyName
FROM topic t left JOIN `user` u ON t.authorId = u.id
left JOIN `user` u1 ON t.lastReplyId = u1.id