我有兩個表raw_materials
和raw_materials_moves
。選擇每個項目的最後3行
raw_materials
有場
id, name
raw_materials_moves
有這個領域
id, raw_material_id, price, created
所以,我需要每種原料的select
最後3個移動
我有這樣的查詢,但doesn't工作
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
我真的是新的Mysql,你能舉個例子嗎? – borfrank