Having an issue with a join code where the code is executing but is giving me a warning that it is truncating my PROD_INTO_DATE but I noticed that it was entered into the PROD_CAT_CD column.
INSERT INTO `goac`.`product` (`PROD_ID`, `PROD_NM`, `PROD_SKU_NO`, `PROD_CAT_CD`, `PROD_PACKAGE_SIZE_NO`, `PROD_INTRO_DT`) select distinct c.PROD_ID, c.PROD_NM, c.PROD_SKU_NO,c.PROD_INTRO_DT, s.PROD_PACKAGE_SIZE_NO, s.PROD_CAT_CD FROM ods_product AS c join ods_sale_large as s on s.PROD_NM = c.PROD_NM; select * from product
Where the data is being inserted
The PROD_CAT_CD has data that should be there.
And where the join is coming from it should be fine because it sees the date as date.
Advertisement
Answer
You need to insert the columns in the same order as in the insert
column list:
INSERT INTO `goac`.`product` (`PROD_ID`, `PROD_NM`, `PROD_SKU_NO`, `PROD_CAT_CD`, `PROD_PACKAGE_SIZE_NO`, `PROD_INTRO_DT`) select distinct c.PROD_ID, c.PROD_NM, c.PROD_SKU_NO, s.PROD_CAT_CD, s.PROD_PACKAGE_SIZE_NO, c.PROD_INTRO_DT from ods_product c join ods_sale_large s on s.PROD_NM = c.PROD_NM;
Once I had a colleague that I respected very much. She initially had the same confusion with insert
. . . although you list the columns and the select
also has column names, the matching is by position rather than by name.