我已写下此查询
pr($this->User->find('all',array('fields'=>array('DISTINCT User.last_name','User.first_name')))); die;
Array
(
[0] => Array
(
[User] => Array
(
[last_name] => singh
[first_name] => admin
)
)
[1] => Array
(
[User] => Array
(
[last_name] => singh
[first_name] => jaskaran
)
)
)
它不起作用但是当我从字段中删除first_name然后它就是工作
pr($this->User->find('all',array('fields'=>array('DISTINCT User.last_name')))); die;
结果
Array
(
[0] => Array
(
[User] => Array
(
[last_name] => singh
)
)
)
但我需要两个具有明显的cakephp 2 +
的字段答案 0 :(得分:1)
我想你要检索last_name
& firstname
为lastname
的用户表中的DISTINCT
。
$users = $this->User->find('all', array(
'fields' => array('User.last_name', 'User.first_name'),
'group' => array('User.firstname')
));
输出:
Array
(
[0] => Array
(
[User] => Array
(
[last_name] => singh
[first_name] => admin
)
)
)
请查看以下mySQL select one column DISTINCT, with corresponding other columns