加入问题

时间:2019-12-02 02:59:38

标签: sql oracle

即使没有订购成分,也要列出所有成分的成分ID,名称,订购日期,数量和单位(在一列中)(提示:使用外部联接)

SELECT ingredient_id, ingredient_name, date_ordered, CONCAT(quantity, unit) AS "Quantity & Unit" 
FROM ingredient ing 
LEFT OUTER JOIN ingredient_purchase_list ing2 ON ing.ingredient_id = ing2.ingredient_id 
ORDER BY ingredient_id; 

(模糊地定义了说法)

2 个答案:

答案 0 :(得分:2)

file上指定表格alias

columns

答案 1 :(得分:1)

从查询中看,看来您肯定遇到了列名问题。

您需要为列赋予别名,如下所示:

SELECT ing.ingredient_id, ing.ingredient_name, ing2.date_ordered, CONCAT(ing2.quantity, ing2.unit) AS "Quantity & Unit" 
FROM ingredient ing 
LEFT OUTER JOIN ingredient_purchase_list ing2 ON ing.ingredient_id = ing2.ingredient_id 
ORDER BY ing.ingredient_id;

干杯!