我有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 關注
- 140 瀏覽
添加回答
舉報
0/150
提交
取消