加入查询使用两个表,其中条件在cake php? [英] Join query using two table with where condition in cake php?

查看:213
本文介绍了加入查询使用两个表,其中条件在cake php?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们如何使用两个表格来处理连接查询,其中条件在cake php?

How we can write Join query using two table with where condition in cake php?

推荐答案

>
如果能帮助你,请检查这个

You can!!
check this if it would help you

$table = 'table_name';
    $query['conditions'] = array($table.'.entity_id' => $entity_id, $table.'.is_active' => 1);

        $query['fields'] = array('creator.first_name AS cf_name', 'creator.last_name AS cl_name', 'creator.email AS c_email', 'usr.first_name', 'usr.last_name',
            $table.'.id AS id', $table.'.guid', $table.'.updated_date',
            'usr.email AS email');

        // To do joining to get attribute with value
        $query['joins'] = array(
            array(
                    'table' => $this->user,
                    'alias' => 'usr',
                    'type' => 'INNER',
                    'conditions' => array('usr.id = '.$table.'.user_id')
                ),
                array(
                    'table' => $this->user,
                    'alias' => 'creator',
                    'type' => 'INNER',
                    'conditions' => array('creator.id = '.$table.'.creator_id')
                ),
        );
        $query['order'] = array($table.'.updated_date' => 'DESC');

        // Cache implementation
        $result = $this->find('all', $query);

这篇关于加入查询使用两个表,其中条件在cake php?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆