开发者

Duplicate Data invalid identifier

My query is showing all possible combinations of results for this query when i use query builder.

select   
     "PURCHASEDETAIL"."PMID" as "PMID",
     "PURCHASEDETAIL"."CUSTOMER_ID" as "CUSTOMERID",
     "PRODUCT"."DESCRIPTION" as "DESCRIPTION",
     "PRO开发者_开发问答DUCT"."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

When I enter the above info to pull info from 4 table I get the below error.

ORA-00904: "PURCHASEDETAIL"."CUSTOMER_ID": invalid identifier

Any ideas why?


1) Even though you are aliasing the "CUSTOMER_ID" with "CUSTOMERID" when displaying the results, you should still use the "CUSTOMER_ID" (actual column name) in the join condition. If you have an outer query which does further joins..filters..and so on, you can use the alias "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

Use..

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

or

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

2) Probably not related to your question.. but..

The second left join

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

shouldn't this condition be on supplier.customerid instead? (if the column name is the same?)

__* Update based on column name assumptions *--------

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)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜