2
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查询是这样的:SQL查询订购和使用GROUP BY
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"
+1为正确答案,而走样表。 –