我有2张桌子+----+------------+------------+| id | first_name | date |+----+------------+------------+| 1 | Bob | 01/01/2019 |+----+------------+------------+| 2 | June | 01/05/2019 |+----+------------+------------+和+----+--------+---------+------------+| id | userID | comment | date |+----+--------+---------+------------+| 1 | 1 | Hello | 02/01/2019 |+----+--------+---------+------------+| 2 | 1 | Again | 02/02/2019 |+----+--------+---------+------------+| 3 | 2 | Howdy | 02/03/2019 |+----+--------+---------+------------+我想获得所有名字为 Bob 的用户的结果,并将最新的评论附加到该结果。我可以$users = SELECT * FROM Users WHERE id = 1然后foreach($users as $user){ $comment = Comment::where("userID", $user->id)->first(); if($comment != null){ $user->comments = $comment->$comment; }}但是,如果 $users 中有很多结果,它会很慢
- 2 回答
- 0 关注
- 107 浏览
添加回答
举报
0/150
提交
取消