这是我的疑问:
SELECT DISTINCT customer.customer_ID, customer.`Name`, customer.Home_Phone,
customer.Work_Phone, inventory.`condition`, inventory.equip_name
FROM customer
INNER JOIN rental_agreement R ON customer.customer_ID = R.customer_ID
INNER JOIN rental_detail E ON E.agreement_num = R.agreement_number
INNER JOIN inventory I ON E.Item_number = I.item_Number
WHERE E.real_return IS NOT NULL;
当我从select部分删除两个库存列时,它按预期工作,但当我将它们添加回来时,它告诉我这两列不存在。
P.S。此外,查询可能实际上不起作用,因为数据库当前是空的,所以如果你看到一些明显的问题,我会很感激,我对SQL有点新鲜:)
答案 0 :(得分:2)
你给表别名,使用select中的别名而不是表名(即,一旦别名,inventory
不存在,但I
会这样做)
SELECT DISTINCT customer.customer_ID,
customer.`Name`,
customer.Home_Phone,
customer.Work_Phone,
I.`condition`,
I.equip_name
FROM customer
INNER JOIN rental_agreement R ON customer.customer_ID = R.customer_ID
INNER JOIN rental_detail E ON E.agreement_num = R.agreement_number
INNER JOIN inventory I ON E.Item_number = I.item_Number
WHERE E.real_return IS NOT NULL;