I have two databases: txdb and rhdb. I am trying to combine PARCEL and WATERID from txdb.event and insert it into rhdb.orders. However, MySQL Workbench shows me this warning:
358 row(s) affected, 52 warning(s):
1062 Duplicate entry '017038003 678108' for key 'orders.PRIMARY'
1062 Duplicate entry '017038003 676789' for key 'orders.PRIMARY'
1062 Duplicate entry '018012018 678348' for key 'orders.PRIMARY'
1062 Duplicate entry '018012018 676903' for key 'orders.PRIMARY'
etc.
As we can see, the last 6 digits are different for the first two rows, which should indicate that they are not duplicates.
The following are some supporting material. This is the create statement for rhdb.orders:
CREATE TABLE 'orders' (
'COMBO' varchar(17) NOT NULL,
'LAT' varchar(10) NOT NULL,
'SG' varchar(10) NOT NULL,
'NAME' varchar(100) NOT NULL,
'PHONE' varchar(10) NOT NULL,
'FLOW' double NOT NULL,
'HOURS' double NOT NULL,
'ACRE' double NOT NULL,
'CROP' varchar(2) NOT NULL,
'TYPE' varchar(2) NOT NULL,
'DATE' date NOT NULL,
'TRANTIME' int NOT NULL,
'EX' varchar(1) DEFAULT NULL,
'FINAL' varchar(1) NOT NULL,
'COMMENT' varchar(255) DEFAULT NULL,
'SBXCFS' double DEFAULT NULL,
'DELETED' varchar(1) DEFAULT NULL,
'SA' varchar(2) NOT NULL,
'HEAD' varchar(4) DEFAULT NULL,
'EST_START' datetime DEFAULT NULL,
'EST_FINISH' datetime DEFAULT NULL,
'WDO_NOTES' varchar(255) DEFAULT NULL,
PRIMARY KEY ('COMBO'),
UNIQUE KEY 'COMBO_UNIQUE' ('COMBO')
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
This is the create statement for txdb.event:
CREATE TABLE 'event' (
'ID' int NOT NULL,
'ISPEC' varchar(5) NOT NULL,
'WTIDNO' varchar(5) NOT NULL,
'PARCEL' varchar(9) NOT NULL,
'WATERID' varchar(6) NOT NULL,
'LATERAL' varchar(10) NOT NULL,
'SIDEGATE' varchar(10) NOT NULL,
'NAME1' varchar(100) NOT NULL,
'PHONE1' varchar(10) NOT NULL,
'RQSTFLO' double NOT NULL,
'HOURS' double NOT NULL,
'CROP1' varchar(2) NOT NULL,
'IRRIGTYP' varchar(2) NOT NULL,
'EVENT_TRANDATE' date DEFAULT NULL,
'TRANTIME' int DEFAULT NULL,
'EXCESSIVEORDER' varchar(1) DEFAULT NULL,
'DELETED' varchar(1) DEFAULT NULL,
'SERVAREA' varchar(2) DEFAULT NULL,
'FLOWID' varchar(5) DEFAULT NULL,
'COMMENT1' varchar(128) DEFAULT NULL,
'COMMENT2' varchar(127) DEFAULT NULL,
PRIMARY KEY ('ID'),
UNIQUE KEY 'WATERID_UNIQUE' ('WATERID')
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
This is the query I am using to insert everything from txdb into rhdb.orders:
INSERT IGNORE INTO rhdb.orders
('COMBO', 'LAT', 'SG', 'NAME', 'PHONE', 'FLOW', 'HOURS', 'ACRE', 'CROP', 'TYPE', 'DATE', 'TRANTIME', 'EX', 'FINAL', 'COMMENT', 'SBXCFS', 'DELETED', 'SA')
SELECT
CONCAT(TRIM(event.PARCEL), ' ', TRIM(event.WATERID)) AS 'COMBO',
event.LATERAL AS 'LAT',
event.SIDEGATE AS 'SG',
event.NAME1 AS 'NAME',
event.PHONE1 AS 'PHONE',
event.RQSTFLO AS 'FLOW',
event.HOURS,
parcd.PIACR AS 'ACRE',
event.CROP1 AS 'CROP',
event.IRRIGTYP AS 'TYPE',
event.event_TRANDATE AS 'DATE',
event.TRANTIME,
event.EXCESSIVEORDER AS 'EX',
parcd.LASTIRRIGATION AS 'FINAL',
CONCAT(event.COMMENT1,' ',event.COMMENT2) AS 'COMMENT',
sbxdtl.SBXCFS,
event.DELETED,
event.SERVAREA AS 'SA'
FROM
txdb.event event
JOIN txdb.parcd parcd ON event.WTIDNO = parcd.TIDPNUMB
JOIN txdb.sbxdtl sbxdtl ON event.FLOWID = sbxdtl.FLOWID;
Since MySQL Workbench says that I have duplicates, I tried searching for them using this query:
SELECT
CONCAT(TRIM(PARCEL), ' ', TRIM(WATERID)) AS COMBO,
COUNT(*)
FROM txdb.event
GROUP BY COMBO
HAVING COUNT(*) > 1;
This query returned 0 rows, which indicates that I should not be receiving the warning message that I wrote above.
Later, I also tried inserting the data into temporary table, and then from temporary table into rhdb.orders, but it also gives me duplicate warnings.
However, when I tried just combining PARCEL with WATERID and inserting it into rhdb.orders as COMBO, it did not give me any duplicate warnings, instead it showed me the error message for not null fields. I used this query:
INSERT IGNORE INTO rhdb.orders
('COMBO')
SELECT
CONCAT(TRIM(PARCEL) COLLATE utf8mb4_general_ci, ' ', TRIM(WATERID) COLLATE utf8mb4_general_ci) AS COMBO
FROM
txdb.event event;
Here is the error message:
358 row(s) affected, 13 warning(s):
1364 Field 'LAT' doesn't have a default value
1364 Field 'SG' doesn't have a default value
1364 Field 'NAME' doesn't have a default value
...
Records: 358 Duplicates: 0 Warnings: 13
I don't understand how to fix and what to fix, please help!