Php Geek
Php Geek

Reputation: 1107

getting a distinct value from db through cake-php

Hi i want to get distinct values from a particular column from cakephp.

This is what i have tried:-

 $new_data =$this->Event->findAll(null, 'DISTINCT events.source');

Event- is the name of my model.
events- is my table name in db.
Source:- is the column name from which i want to fetch values.

I dnt knw what is wrong in the query, can anyone help me out

Upvotes: 0

Views: 230

Answers (3)

user1933865
user1933865

Reputation:

$this->Event->find('all', array('group' => 'Event.source'));

Upvotes: 1

Php Geek
Php Geek

Reputation: 1107

$this->Event->find('all', array('group' => 'Event.source'));

Upvotes: 0

yourdeveloperfriend
yourdeveloperfriend

Reputation: 1590

findAll is not actually a cakephp method. What you want to do is:

$this->Event->find('all', array('fields' => 'DISTINCT Event.source'));

http://book.cakephp.org/2.0/en/models/retrieving-your-data.html#find-all

Upvotes: 2

Related Questions