본문 바로가기

에러/MySql

[에러] <MySQL> Error Code: 1052

쿼리

SELECT PRODUCT_ID, PRODUCT_NAME, PRODUCT_DETAIL, SALE_PRICE, INGREDIENT, DOSAGE, EXPIRATION_DATE, c.CATEGORY_NAME, i.IMAGE_PATH
FROM PRODUCT p
JOIN PRODUCT_CATEGORY pc ON p.PRODUCT_ID = pc.PRODUCT_ID
JOIN CATEGORY c ON pc.CATEGORY_ID = c.CATEGORY_ID
JOIN PRODUCT_IMAGE pi ON p.PRODUCT_ID = pi.PRODUCT_ID
JOIN IMAGE i ON pi.IMAGE_ID = i.IMAGE_ID
WHERE PRODUCT_ID = 245;

내용

◎ Column 'PRODUCT_ID' in field list is ambiguous 0.000 sec


원인

◎ JOIN을 사용할 경우  외부키로 이용되는 공통된 컬럼이 존재한다.

◎ 이러한 컬럼들을 사용할 때는 테이블 명을 명시해주어야 한다.


해결

SELECT p.PRODUCT_ID, p.PRODUCT_NAME, p.PRODUCT_DETAIL, p.SALE_PRICE, p.INGREDIENT, p.DOSAGE, p.EXPIRATION_DATE, c.CATEGORY_NAME, i.IMAGE_PATH
FROM PRODUCT p
JOIN PRODUCT_CATEGORY pc ON p.PRODUCT_ID = pc.PRODUCT_ID
JOIN CATEGORY c ON pc.CATEGORY_ID = c.CATEGORY_ID
JOIN PRODUCT_IMAGE pi ON p.PRODUCT_ID = pi.PRODUCT_ID
JOIN IMAGE i ON pi.IMAGE_ID = i.IMAGE_ID
WHERE p.PRODUCT_ID = 245;

 

 

'에러 > MySql' 카테고리의 다른 글

[에러] <MySQL> Incorrect result size :  (0) 2024.03.15