【问题标题】:Which join is actually used behind the join() of laravel?laravel 的 join() 后面实际使用的是哪个 join?
【发布时间】:2021-07-10 07:53:20
【问题描述】:

我只想知道在 Laravel join() 的幕后会使用哪个 join。是leftjoin()、rightjoin()还是innerjoin()?

例如:

这里实际上将使用什么连接?

$friends_votes = DB::table('users')
    ->join('votes', 'votes.user_id', '=', 'users.id')
    ->where('votes.user_id',1);

【问题讨论】:

标签: mysql laravel join


【解决方案1】:

innerJoin 见laravel doc:

如果你想要left or right join,你应该严格使用它们:

右加入:

$friends_votes = DB::table('users')
    ->rightJoin('votes', 'votes.user_id', '=', 'users.id')

左连接:

$friends_votes = DB::table('users')
    ->leftJoin('votes', 'votes.user_id', '=', 'users.id')

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-08-09
    • 1970-01-01
    • 2014-11-17
    • 2019-08-01
    • 1970-01-01
    • 2022-01-20
    • 2020-06-06
    相关资源
    最近更新 更多