Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Using DISTINCT keyword of sql in cakephp

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 803
    Comment on it

    As we all might know that selecting all records from the database in cakephp can be done using the find("all") method, But there are chances of duplicate records may appear.

    To remove the duplicate records on selecting all records we use distinct keyword in the query but in cakephp here is a way to write it as :

    $results = $this->LogfileRecord->find('all',
        array('fields'=>array('DISTINCT date'), 
              'order'=>array('date DESC'))
    );
    

    in the above we have used distinct keyword in the array for date field. If we look for the simple query it will be as :

    select distinct(date) from logfile_records order by date DESC;
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: