这是我当前的查询:
SELECT * FROM images T
JOIN boxes_items T2
ON T.ITEM_ID = T2.ITEM_PARENT_ID
WHERE T2.ITEM_ID = '$image_id'
我还需要从名为“boxes”的表中全选,其中 box_id 取自 box_items。
如何将此添加到查询中?
尝试这个
SELECT T.* , T2.* , T3.* FROM images T
JOIN boxes_items T2 ON T.ITEM_ID = T2.ITEM_PARENT_ID
JOIN boxes T3 ON T3.box_id = t2.box_id
WHERE T2.ITEM_ID = '$image_id'
SELECT *
FROM images T
JOIN boxes_items T2 ON T.ITEM_ID = T2.ITEM_PARENT_ID
JOIN boxes AS b ON b.box_id = t2.box_id
WHERE T2.ITEM_ID = '$image_id'
你真的不应该使用*
它,它会给你带来更多的麻烦而不是它的价值。特别是因为您的查询中有多个表。
反正:
Select T.*, T2.*, T3.*
from images T
join boxes_items T2 on T.ITEM_ID = T2.ITEM_PARENT_ID
join boxes T3 on T3.box_id = T2.box_id
WHERE T2.ITEM_ID = '$image_id'