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?
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With