products
id product_cat_id product_type_id title ordering
1 42 1 "a" 1
2 42 1 "b" 2
3 42 2 "c" 1
4 43 1 "d" 1
product_cats
id title ordering
1 "n" 1
2 "b" 2
3 "h" 3
product_types
id title ordering
1 "b" 1
2 "n" 2
3 "m" 3
Мой SQL-запрос такой:
SELECT
`products`.`title`,
`product_types`.`title`
FROM
`products`,
`product_cats`,
`product_types`
WHERE
`products`.product_cat_id=42
ORDER BY `product_types`.`ordering`,`products`.`ordering` ASC
Но мой SQL-запрос возвращает все заголовки, которые даже не имеют product_cat_id, равный 42. Я пытался использовать group_by, но он все еще не удался.
Я ищу это:
product_title product_type_title
"a" "b"
"b" "b"
"c" "n"