我有两张桌子raw_materials
和raw_materials_moves
。
raw_materials
有字段
id, name
raw_materials_moves
有这个字段
id, raw_material_id, price, created
所以,我需要对select
每种原材料进行 3 次移动
我有这个查询,但不工作
SELECT a.*, b.price, b.created
FROM raw_materials a
LEFT JOIN
(SELECT price, raw_material_id, created FROM raw_material_moves ORDER BY created DESC LIMIT 3) b
ON b.raw_material_id=a.id
ORDER BY a.id