我有一个三向连接,可以获取正确的行数但返回空值。 表名和列名是正确的。在最后一次连接中,s.int确实与SOD.orderID匹配。 我只用第一次加入测试它就可以了。 [!前缀]是平台要求,不会影响结果。可以将两个表连接到一个表吗?
'SELECT S.name, S.price, SD.store_value AS type, SOD.quantity
FROM [!prefix]store as S
JOIN [!prefix]storedetail as SD
ON S.`int` = SD.storeID
JOIN [!prefix]store_orders_details as SOD
ON S.`int` = SOD.orderID
WHERE S.`int` = ?';
答案 0 :(得分:0)
如果我理解正确,在最后一个表中没有足够的数据要合并。试试这个:
'SELECT S.name, S.price, SD.store_value AS type, SOD.quantity
FROM [!prefix]store as S
JOIN [!prefix]storedetail as SD
ON S.`int` = SD.storeID
LEFT JOIN [!prefix]store_orders_details as SOD
ON S.`int` = SOD.orderID
WHERE SOD.orderID = ?';