gpt4 book ai didi

mysql - 如何像这样组合 2 个 MySQL 表? (多对一关系)

转载 作者:行者123 更新时间:2023-11-29 08:51:34 24 4
gpt4 key购买 nike

我有这样的 UserComments 表:

1 | Frank | hello world
2 | Jane | Hi there
3 | Frank | this is my comments
4 | Frank | I think I need some sleep
5 | Jason | I need to buy new MacBook
6 | Jane | Please invite my new Blackberry PIN

另一方面,我有 FriendList 表包含:

1 | Jason
2 | Jane

假设我 friend 的 ID 始终介于 1 和 5 之间。

由于 Frank 不是我的 friend ,所以我看不到他的评论。如何合并这样的表(ORDER BY UserComments.ID DESC):

1 | Jane | Please invite my new Blackberry PIN
2 | Jason | I need to buy new MacBook
3 | Jane | Hi there

谢谢。

最佳答案

试试这个:

    SELECT A.ID, B.UserName, B.Comment 
FROM FriendList A
INNER JOIN UserComments B ON A.ID = B.ID
ORDER BY A.ID DESC

关于mysql - 如何像这样组合 2 个 MySQL 表? (多对一关系),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11069865/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com