Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting SQL Error: ORA-00957: duplicate column name, while creating view

Tags:

sql

oracle11g

I am trying to make a view, but I am getting a duplicate column name error. If I run the select query separately, then the query returns a result like:

SELECT distinct app.APP_REF_NO, app.APP_STATUS, app.APP_DT, app.ATTEND_STAFF,
                app.ATTEND_BRANCH, app.PRODUCT_TYPE, cust.CUST_ID, 
                cust.APP_JOINT_T, cust.ID1_TYPE, cust.ID1, cust.ID2_TYPE, 
                cust.ID2, cust.FIRST_NAME, cust.LAST_NAME, cust.FULL_NAME, 
                cust.FULL_NAME_CAP, cust.DOB, fac.FACILITY_NO, fac.PRODUCT_TYPE,
                fac.PRODUCT_CODE, fac.MAIN_PROD_IND, fac.AMT_APPLIED
FROM 
    LOSA_APP app 
LEFT JOIN 
    LOSA_CUST cust 
ON
    cust.APP_REF_NO = app.APP_REF_NO
LEFT JOIN 
   LOSA_FACILITIES fac 
ON
    fac.APP_REF_NO = app.APP_REF_NO
LEFT JOIN 
    OS_CURRENTSTEP STEP 
ON
    STEP.REF_ID = app.APP_REF_NO
   WHERE (app.APP_STATUS ='P' OR app.APP_STATUS ='T' OR 
         ((app.APP_STATUS='R' OR app.APP_STATUS='S') AND STEP.STEP_NAME='011'));

This query works fine. But when I try to run it as a view like:

CREATE VIEW basit_test1 AS
SELECT distinct app.APP_REF_NO, app.APP_STATUS, app.APP_DT, app.ATTEND_STAFF,
                app.ATTEND_BRANCH, app.PRODUCT_TYPE, cust.CUST_ID, 
                cust.APP_JOINT_T, cust.ID1_TYPE, cust.ID1, cust.ID2_TYPE, 
                cust.ID2, cust.FIRST_NAME, cust.LAST_NAME, cust.FULL_NAME, 
                cust.FULL_NAME_CAP, cust.DOB, fac.FACILITY_NO, fac.PRODUCT_TYPE,
                fac.PRODUCT_CODE, fac.MAIN_PROD_IND, fac.AMT_APPLIED
FROM 
    LOSA_APP app 
LEFT JOIN 
    LOSA_CUST cust 
ON
    cust.APP_REF_NO = app.APP_REF_NO
LEFT JOIN 
   LOSA_FACILITIES fac 
ON
    fac.APP_REF_NO = app.APP_REF_NO
LEFT JOIN 
    OS_CURRENTSTEP STEP 
ON
    STEP.REF_ID = app.APP_REF_NO
   WHERE (app.APP_STATUS ='P' OR app.APP_STATUS ='T' OR 
         ((app.APP_STATUS='R' OR app.APP_STATUS='S') AND STEP.STEP_NAME='011'));

Then I get the duplicate column name error. Why am I getting this error?

like image 905
Basit Avatar asked Mar 25 '13 10:03

Basit


1 Answers

you have two product_type columns:

fac.PRODUCT_TYPE

and

app.PRODUCT_TYPE

you should alias one of them eg

app.PRODUCT_TYPE app_prod_type
like image 153
DazzaL Avatar answered Sep 30 '22 07:09

DazzaL