我正在尝试SELECT
在三个关系表上创建一个,如下所示:
table_materials
-> material_id
- material_name
table_props
-> prop_id
- prop_name
table_materials_props
- row_id
-> material_id
-> prop_id
- prop_value
在我的页面上,我想得到这样的结果,但我的查询有一些问题:
material prop A prop B prop C prop D prop E
wood 350 NULL NULL 84 16
iron NULL 17 NULL NULL 201
copper 548 285 99 NULL NULL
所以查询应该返回如下内容:
material prop_name prop_value
wood prop A 350
wood prop B NULL
wood prop C NULL
wood prop D 84
wood prop E 16
// and go on with others rows
我想使用类似的东西:
SELECT *
FROM table_materials AS m
INNER JOIN table_materials_props AS mp
ON m.material_id = mp.material_id
INNER JOIN table_materials_props AS p
ON mp.prop_id = p.prop_id
ORDER BY p.prop_name
问题是查询不返回NULL
值,我需要相同的prop
顺序来处理所有materials
道具值NULL or not
我希望这个例子很清楚!