ftdxl 2015-10-17 14:42:09 22023次浏览 3条回复 0 2 0

问题: 有个查询语句需要用到left join bb on aa.id=bb.id and cc.id=aa.id 请问YII2框架有哪个方法可以实现

觉得很赞
  • 回复于 2015-10-18 16:27 举报

    顶一下顶一下顶一下

    觉得很赞
  • 回复于 2015-10-19 01:12 举报

    with 方法可以帮你解决。

  • 回复于 2015-10-23 23:46 举报
    $query = (new \yii\db\Query())
                ->select('a.id as id,title,create_time,modify_time,username,name')
                ->from('yii_article AS a')
                ->leftJoin('yii_user AS u','u.id = a.user_id')
                ->leftJoin('yii_category AS c','c.id = a.category_id')
                ->where(['c.name'=>'新闻分类'])
                ->limit(4)
                ->orderBy('id DESC')
                ->All();
    
    1 条回复
    回复于 2018-08-12 19:04 回复

    orderBy()里面也需要指定一下比较妥当一点例如['c.id'=>SORT_DESC]

    , 觉得很赞
您需要登录后才可以回复。登录 | 立即注册