Mysql query different group by

Posted by solomongaby on Stack Overflow See other posts from Stack Overflow or by solomongaby
Published on 2010-04-22T08:36:51Z Indexed on 2010/04/22 8:43 UTC
Read the original article Hit count: 301

Filed under:
|
|
|

Hello i have a products table that contains normal products and configurable product

It has a basic stucture of:

  • id
  • name
  • price
  • configurable ('yes', 'no')
  • id_configuration

Normal products have configurable no and 0 as id configuration, and configurable products have it set to yes and have the same id_configuration value.

The current query is:

SELECT `products`.* 
FROM `products`, `categories`, `product_categories` 
WHERE `categories`.`id` = 23 AND 
      `products`.`id` = `product_categories`.`id_product` AND 
      `categories`.`id` = `product_categories`.`id_category` AND 
      `products`.`active` = 'yes' AND 
ORDER BY `pos_new` ASC, `created` DESC LIMIT 0,20

I was wondering if there is a way to group by id_configuration, but only for the configurable products. The reason is that i want only one of the configuration products to show in search. I was thinking i could do a join, but was wondering if there is a way to do some kind of special group by. For example for configurable yes the field should be id_configuration otherwise it should be the id field

Thanks a lot for any sugestions

© Stack Overflow or respective owner

Related posts about mysql

Related posts about mysql-query