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 SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use
near '.`count`

Tell me please how to get result without this additional array.


On May 9, 11:20 pm, Alexey Kuimov <[EMAIL PROTECTED]> wrote:
> 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('Vendor.name', 'Vendor.safe', 'COUNT(Model.vendor_id)
> AS `Vendor`.`count`');
> $conditions = 'GROUP BY Vendor.id';
> $order = 'Vendor.name ASC';
> $result = $this->Vendor->findAll($conditions, $fields, $order);
>
> On May 6, 5:32 pm, geoffriley <[EMAIL PROTECTED]> wrote:
>
> > 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:
>
> > SELECT
> >   `Vendor`.`name`,
> >   `Vendor`.`safe`,
> >   COUNT(Model.vendor_id) AS `Vendor`.`count`
> > FROM
> >   `vendors` AS `Vendor`
> >   LEFT JOIN `models` AS `Model` ON `Model`.`vendor_id` = `Vendor`.`id`
> > GROUP BY `Vendor`.`id`
> > ORDER BY `Vendor`.`name`  ASC
>
> > As an aside, I think you can safely replace
> >   ON `Model`.`vendor_id` = `Vendor`.`id`
> > with
> >   USING (`id`)
> > given that only two tables are involved.  But I could be wrong on that
> > one. :-)
>
> > Hope that helps.
>
> > Geoff


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
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