如何使用左连接构造解决此问题的mySQL查询?
Feed Table
-id
-lastpost_id (The id of the user from USER TABLE who last posted)
-firstpost_id (The id of the user from USER TABLE who first posted)
User Table
-id
-name我想要一张那样的桌子。
Result
-id
-lastpost_id
-lastpost_name
-firstpost_id
-firstpost_name发布于 2011-03-09 07:12:53
select *, a.name as lastpost_name, b.name as firstpost_name from Feed f
left join user a on f.lastpost_id=a.id
left join user b on f.firstpost_id=b.id诀窍是使用左连接,然后将表别名为a或b。这样,您可以对同一个表进行多个连接
https://stackoverflow.com/questions/5239475
复制相似问题