sql query help join (i think)

Posted by milan on Stack Overflow See other posts from Stack Overflow or by milan
Published on 2011-11-11T17:42:18Z Indexed on 2011/11/11 17:50 UTC
Read the original article Hit count: 110

Filed under:
|
|

I am having trouble figuring our how I can get results only when products.published, product_types.published, and product_cats.published = 1 but my query isn't working. Please help:

SELECT 
  `products`.`title`,
  `products`.`menu_id`,
  `products`.`short_description`,
  `products`.`datasheet_icon`,
  `products`.`datasheet`,
  `products`.`ordering`,
  `products`.`product_type_id`,
  CASE WHEN CHAR_LENGTH(`products`.`alias`)
    THEN CONCAT_WS(':', `products`.`id`, `products`.`alias`) 
    ELSE `products`.`id` 
  END AS slug 
FROM 
  `products`, 
  `product_cats`,
  `product_types`
WHERE 
  `products`.published=1 AND
  `product_cats`.published=1 AND
  `product_types`.published=1 AND
  `products`.`product_cat_id`='42' AND
  `product_types`.`id` IN (1,40,48,49,50)
GROUP BY `products`.`id`
ORDER BY `product_types`.`ordering`, `products`.`ordering`

© Stack Overflow or respective owner

Related posts about mysql

Related posts about sql