Re: Question: Join two tables, count and sort result

2007-05-30 Thread Alexey Kuimov
Sorry for my urgency, but I still have a problem with grouping of query results. With single word name (`count`) for COUNT result I get additional array key [0]: [0] => Array ( [count] => 10 ) If I add table name (`Vendor`.`count` for exampe), I get SQL error #1064: You have an error in your

Re: Question: Join two tables, count and sort result

2007-05-09 Thread Alexey Kuimov
It's strange, but I still get that error message :(. I added backticks, I tried to use `Vendor`.`total` instead `Vendor`.`count` with same negative result. Please, help me with code in controller. Now I'm using this: $this->Vendor->bindModel(array('hasOne'=>array('Model'))); $fields = array('Vend

Re: Question: Join two tables, count and sort result

2007-05-06 Thread geoffriley
You need to quote with backticks the `Vendor`.`count`. Without the backticks the SQL interpreter thinks that you're attempting to use the function count() again, so it's expecting something to count but finds 'FROM' instead: hence the error. So, make your SQL like this, and you should be okay:

Re: Question: Join two tables, count and sort result

2007-05-01 Thread Alexey Kuimov
[mailto:[EMAIL PROTECTED] En nombre > de Alexey Kuimov > Enviado el: Lunes, 30 de Abril de 2007 10:13 a.m. > Para: Cake PHP > Asunto: Re: Question: Join two tables, count and sort result > > In this case I get error message: > > 1064: You have an error in your SQL synta

RE: Question: Join two tables, count and sort result

2007-04-30 Thread Mariano Iglesias
Asunto: Re: Question: Join two tables, count and sort result In this case I get error message: 1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '.`

Re: Question: Join two tables, count and sort result

2007-04-30 Thread Alexey Kuimov
In this case I get error message: 1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '.`count` :-( On Apr 30, 5:45 pm, dardosordi <[EMAIL PROTECTED]> wrote: > Try: > > SELECT `Vendor`.`id`, COUNT(`Model`.`v

Re: Question: Join two tables, count and sort result

2007-04-30 Thread dardosordi
Try: SELECT `Vendor`.`id`, COUNT(`Model`.`vendor_id`) as `Vendor`.`count` FROM `vendors` AS `Vendor` LEFT JOIN `models` AS `Model` ON (`Model`.`vendor_id` = `Vendor`.`id`) WHERE 1=1 GROUP BY `Vendor`.`id` On Apr 29, 3:18 pm, thequietlab <[EMAIL PROTECTED]> wrote: > I don't think so.. > > Baker

Re: Question: Join two tables, count and sort result

2007-04-29 Thread thequietlab
I don't think so.. Bakers, is there a way to do this ? On 29 Kwi, 16:13, Alexey Kuimov <[EMAIL PROTECTED]> wrote: > Ok, thank you very much! All are working right! But I have another > question. Now my result looks like: > Array > ( > [0] => Array > ( > [Vendor] => Array

Re: Question: Join two tables, count and sort result

2007-04-29 Thread Alexey Kuimov
Ok, thank you very much! All are working right! But I have another question. Now my result looks like: Array ( [0] => Array ( [Vendor] => Array ( [name] => Sony ) [0] => Array (

Re: Question: Join two tables, count and sort result

2007-04-29 Thread Alexey Kuimov
thequietlab, thanks for your advise. Now all working fine! But now I get result's array like this: Array ( [0] => Array ( [Vendor] => Array ( [name] => Sony ) [0] => Array (

Re: Question: Join two tables, count and sort result

2007-04-27 Thread thequietlab
ahh.. and if you want to sort it then, just : $this->Vendor->bindModel(array('hasOne'=>array('Model'))); $fields = array('Vendor.id','COUNT(Model.vendor_id)'); $conditions = 'GROUP BY Vendor.id'; $order = 'COUNT(Model.vendor_id) DESC'; $this->Vendor->findAll( $conditions, $fields, $order ); On A

Re: Question: Join two tables, count and sort result

2007-04-27 Thread thequietlab
hey guys, try this : $this->Vendor->bindModel(array('hasOne'=>array('Model'))); $fields = array('Vendor.id','COUNT(Model.vendor_id)'); $conditions = 'GROUP BY Vendor.id'; $this->Vendor->findAll( $conditions, $fields ); This should make a query like this : SELECT `Vendor`.`id`, COUNT(`Model`.`v

Re: Question: Join two tables, count and sort result

2007-04-26 Thread rtconner
Yeah I'm wondering this also. Is there a cake way of going this? Get some sort of count(*)/GROUP BY select using cake associations? On Apr 26, 8:50 am, Alexey Kuimov <[EMAIL PROTECTED]> wrote: > Hello. I'm a beginner in CakePHP and have a question: > > I have two tables: Vendors (id, name) and Mo

Question: Join two tables, count and sort result

2007-04-26 Thread Alexey Kuimov
Hello. I'm a beginner in CakePHP and have a question: I have two tables: Vendors (id, name) and Models (id, vendor_id, name). Could somebody tell me how to get in query result Vendors names and a number of their Model. Also I need sort result by Vendors names or by a number of Models. Now I'm usi