重复数据无效标识符

时间:2011-04-15 18:10:28

标签: sql identifier

当我使用查询构建器时,我的查询显示了此查询的所有可能的结果组合。

select   
     "PURCHASEDETAIL"."PMID" as "PMID",
     "PURCHASEDETAIL"."CUSTOMER_ID" as "CUSTOMERID",
     "PRODUCT"."DESCRIPTION" as "DESCRIPTION",
     "PRODUCT"."PRICE" as "PRICE",
     "PURCHASEDETAIL"."QUANTITY" as "QUANTITY",
     "SUPPLIER"."SUPPLIER_NAME" as "SUPPLIER_NAME",
     "PURCHASEMASTER"."PURCHASE_DATE_TIME" as "PURCHASE_DATE_TIME" 
 from    
     "SUPPLIER"
 left join product
 ON supplier.supplierid = product.supplierid
 left join purchasemaster
 on purchasemaster.customerid = purchasedetail.customerid
 left join purchasedetail
 on purchasedetail.pmid = purchasemaster.pmid

当我输入上述信息从4表中提取信息时,我得到以下错误。

ORA-00904:" PURCHASEDETAIL"。" CUSTOMER_ID":无效标识符

任何想法为什么?

1 个答案:

答案 0 :(得分:2)

1)即使您在显示结果时使用“CUSTOMERID”对“CUSTOMER_ID”进行别名,您仍应在连接条件中使用“CUSTOMER_ID”(实际列名称)。 如果你有一个外部查询,它进一步加入..filters ......等等,你可以使用别名“CUSTOMERID”

select e.empno , d.deptno Department_No
  from scott_emp e,
       scott_dept d
  where d.Department_No = e.deptno;

ORA-00904: "D"."DEPARTMENT_NO": invalid identifier

使用..

select e.empno , d.deptno Department_No
  from scott_emp e,
       scott_dept d
  where d.deptno = e.deptno;

select * from 
(select deptno Department_no,dname
  from scott_dept) d,
  scott_emp e
where d.Department_no = e.deptno

2)可能与你的问题无关......但是......

第二个左连接

<SUPPLIER>...
<PRODUCT>....
LEFT JOIN
           purchasemaster
        ON purchasemaster.customerid = **purchasedetail.customerid**

这个条件不应该在supplier.customerid上吗? (如果列名相同?)

__ *根据列名称假设进行更新* --------

select sup.supplier_name,
       prd.description,
       prd.price,
       prm.purchase_date_time,
       prd.pmid,
       prd.customer_id,
       prd.quantity
  from supplier sup
       left join product prd
            on (sup.supplierid = prd.productid)
       left join purchasedetail prd
            on (prd.productid = product.productid)
       left join purchasemaster prm
            on (prd.purchaseid = prm.purchaseid)