Friday, October 30, 2009

Group by in custom query in drupal

We should Keep in mind the followings when we use group by in custom queries.

ex: SELECT pname, MIN(price) FROM products GROUP BY pname;

1. The column that you GROUP BY must also be in your SELECT statement.
2. Remember to group by the column you want information about and not the one you are applying the aggregate function on. In our above example we wanted information on the pname and the aggregate function was applied to the price column.

No comments:

Post a Comment