我的Oracle数据库中有两个表。
第一个表格是(客户)-
customer_id Customer_name Customer_age Customer_address salary 103 Giriraj Rathi 22 Kolkata 12000 100 Subir Adhikari 22 Bolpur 10000 101 Rakesh Chatterjee 21 Tarkeshwar 8000 102 Jayanta Patra 20 Tarkeshwar 9000 104 Abhi Karmakar 22 Burdwan 8000 105 Mainak Manna 21 Burdwan 9000 106 Subho Gupta 20 Kolkata 10000 107 Aritra Das 23 Kolkata 7000 108 Pradip Paul 22 Kolkata 5000 109 Sourav Banerjee 22 Bolpur 9000
第二张表是(订单):
Order_id Order_date customer_id amount 200 12-03-13 100 1100 201 09-05-13 101 1400 202 07-04-12 103 2500 204 29-05-13 104 2400 203 09-02-13 105 9000 205 18-06-13 106 2100 206 09-07-13 107 1600 207 18-05-13 108 2900 209 18-04-13 109 2400
现在我想同时加入这两个表。所以我使用了查询:
select customer_id, customer_name, customer_address, order_id,order_date, amount from customers, orders where customers.customer_id=orders.customer_id;
我搜索了该错误,并发现当SQL代码本身存在歧义时会发生这种情况,但是在这种情况下,我什么也看不到。
像这样将表名/别名添加到列中总是一个好主意
select c.customer_id, c.customer_name, c.customer_address, o.order_id, o.order_date, o.amount from customers c inner join orders o on c.customer_id = o.customer_id
如果您不这样做,那么数据库将不知道要采用哪一列,并且两个表都有一个名为的列customer_id。
customer_id