需要简单加入方面的帮助
哎呀,
说对了。
SELECT *,t.id AS threadid FROM threads t
LEFT JOIN players p on p.id = t.last_poster
WHERE t.boardid = $boardid
我在线程中有两个名为 posterid
和 lastposterid
的字段。这是话题发起者/最后发帖者的 ID。我想做的是从玩家表中获取他们的名字。
但如何呢?
Oi
Right to the problem.
SELECT *,t.id AS threadid FROM threads t
LEFT JOIN players p on p.id = t.last_poster
WHERE t.boardid = $boardid
I have two fields in threads called posterid
and lastposterid
. Which are the IDs of the thread starter / last poster. What I want to do is to get their names from players table.
But how?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您只需加入玩家表两次,就像这样。
You just need to join to your players table twice, like this.
您可以两次联接同一个表并为该表指定不同的别名。
这假设总是会有第一个和最后一个海报,如果是这种情况,那么您需要一个
INNER JOIN
而不是LEFT JOIN
,您将需要更改select 语句来获取相关字段。You can join to the same table twice and give the table a different alias.
This presumes that there always will be a first and last poster, if this is the case then you want an
INNER JOIN
rather than aLEFT JOIN
, you will need to change the select statement to get the relevant fields.怎么样...
How about...