Hello,

>> I need to convert the following:
>>
>> SELECT *
>> FROM `laps`
>> WHERE `id` = (
>> SELECT `id`
>> FROM `laps` AS `alt`
>> WHERE `alt`.`user_id` = `laps`.`user_id`
>> ORDER BY `lap_time` ASC
>> LIMIT 1 )
>> ORDER BY `lap_time` ASC
>> LIMIT 10

Really? :)

OK, sth like that:

$this->Lap->find('all', array(
        'conditions' => array('Lap.id' => '(SELECT `id` FROM `laps` AS `alt`
WHERE `alt`.`user_id` = `laps`.`user_id` ORDER BY `lap_time` ASC LIMIT
1 )',
        'order' => array('Lap.lap_time' => 'asc'),
        'limit' => 10
));

This way, however, you will have 'laps' table name hardcoded in your
SQL. So you can further rewrite your code to use $this->table instead
of hardcoded 'laps'.

As for the pagination, take a look at the cookbook:
http://book.cakephp.org/view/249/Custom-Query-Pagination

Maybe you can even avoid using custom query pagination? Have a try...

Regards,
Piotr

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected] For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en

Reply via email to