比较两个表中的字段并在cakephp中获取所需值
有人能帮我吗请试试这个比较两个表中的字段并在cakephp中获取所需值,php,cakephp,Php,Cakephp,有人能帮我吗请试试这个 select * from posts where p_id in (select distinct p_id from tabs); $sub=$this->tab->find('all',array('fields'=>array('Distinct (tabs.p_id)'))); $sub1=$this->post->find('all',array('conditions'=>array('post.p_id' IN ('
select * from posts where p_id in (select distinct p_id from tabs);
$sub=$this->tab->find('all',array('fields'=>array('Distinct (tabs.p_id)')));
$sub1=$this->post->find('all',array('conditions'=>array('post.p_id' IN (' .$sub.')')));
$this->set('mov',$sub1);
$db = $this->Post->getDataSource();
$subQuery = $db->buildStatement(
array(
'fields' => array('"Tabs"."p_id"'),
'table' => 'tabs',
'alias' => 'Tabs',
'limit' => null,
'offset' => null,
'joins' => array(),
'conditions' => array(),
'order' => null,
'group' => null
),
$this->Post
);
$subQuery = ' DISTINCT (Tabs.p_id) IN (' . $subQuery . ') ';
$subQueryExpression = $db->expression($subQuery);
$conditions[] = $subQueryExpression;
$this->Post->find('all', compact('conditions'));
$db = $this->Post->getDataSource();
$subQuery = $db->buildStatement(
array(
'fields' => array('"Tabs"."p_id"'),
'table' => 'tabs',
'alias' => 'Tabs',
'limit' => null,
'offset' => null,
'joins' => array(),
'conditions' => array(),
'order' => null,
'group' => null
),
$this->Post
);
$subQuery = ' DISTINCT (Tabs.p_id) IN (' . $subQuery . ') ';
$subQueryExpression = $db->expression($subQuery);
$conditions[] = $subQueryExpression;
$this->Post->find('all', compact('conditions'));
$sub1=$this->post->find('all',array('conditions'=>array('post.p_id IN ( select distinct p_id from tabs)' )));