表名称:功能MySQL的左连接不工作如我所料
+--------+----------+
| fea_id | fea_name |
+--------+----------+
| 1 | Price |
| 2 | Height |
| 3 | Weight |
+--------+----------+
表名:property_meta
+----+--------+--------+-------+
| id | fea_id | pro_id | value |
+----+--------+--------+-------+
| 100 | 1 | 300 | 2500 |
| 200 | 2 | 300 | 300 |
|
+----+--------+--------+-------+
我的查询
SELECT * FROM feature LEFT JOIN property_meta ON feature.fea_id = property_meta.fea_id where property_meta.pro_id=300 GROUP by feature.fea_id ORDER BY feature.fea_id ASC
预期结果
+--------+--------+-------+
| fea_id | pro_id | value |
+--------+--------+-------+
| 1 | 300 | 2500 |
| 2 | 300 | 300 |
| 3 | 300 | NULL |
+--------+--------+-------+
但我得到没有最后一行。 我需要最后一行也。我如何修改我的查询以获取最后一行?
这意味着即使在属性元表中没有值,我也需要获取Feature表的所有行。
为什么pro_id为300 for fea_id = 3? –