zoukankan      html  css  js  c++  java
  • laravel whereNotIn where子查詢

    子查詢寫法

    $stores = Stores::select('id','name')->whereNotIn('id', function ($query) use($id){
                $query->select('stores_id')->from('fook_article_stores')->where('fook_article_stores.article_id', $id);
            })->get();
    Stores::where('verification_pass',$verification_pass)->where('id','<>',$id)->where('business_id', function ($query) use($id){
                    $query->select('business_id')->from('fook_stores')->where('fook_stores.id', $id);
                })->get();

    laravel WhereNotIn 高效写法

    • Relation 表结构

      • id
      • userId
      • toUserID
      • relation
    • 要求:筛选出没有与本用户建立关系的用户

    • 高效写法

    $users = User::whereNotIn('id', function ($query) use($user){
                $query->select('toUserId')->from('relation')->where('relation.userId', $user->id);
    });
    • 低效率写法
    $actionRelationsArray = Relation::select('toUserId')->where('userId', $user->id)->get()->pluck('toUserId');
    $users = User::whereNotIn('id', $actionRelationsArray);


  • 相关阅读:
    layout布局
    窗口、easyui-window、easyui-panel、easyui-linkbutton
    FASTJSON
    Insert title here
    Insert title here
    Scala并发编程
    scala中java并发编程
    scala调用外部命令
    scala正则表达式
    scala占位符_的用法
  • 原文地址:https://www.cnblogs.com/clubs/p/10276969.html
Copyright © 2011-2022 走看看