I am using mysql
and I want to check the duplicate rows between two tables. I used join
but it's taking too much time as there are millions of records (for example staging table has 800k records while the main table has around 100 million records).
The query I am using is as follow :
INSERT INTO
tblspduplicate
SELECT
T2.SP,T1.FileImportedDate,T2.XYZFileName
FROM
tblspmaster T1
INNER JOIN
tblstaging T2
ON
T1.SP=T2.SP;
CREATE TABLE `tblspmaster` (
`CSN` bigint(20) NOT NULL AUTO_INCREMENT,
`SP` varchar(50) NOT NULL,
`FileImportedDate` date NOT NULL,
`XYZFileName` varchar(50) NOT NULL,
`XYZBatch` varchar(50) NOT NULL,
`BatchProcessedDate` date NOT NULL,
`ExpiryDate` date NOT NULL,
`Region` varchar(50) NOT NULL,
`FCCity` varchar(50) NOT NULL,
`VendorID` int(11) NOT NULL,
`LocationID` int(11) NOT NULL,
PRIMARY KEY (`CSN`)
) ENGINE=InnoDB AUTO_INCREMENT=7484570 DEFAULT CHARSET=latin1;
CREATE TABLE `tblstaging` (
`CSN` bigint(20) NOT NULL AUTO_INCREMENT,
`SP` varchar(50) NOT NULL,
`FileImportedDate` date NOT NULL,
`XYZFileName` varchar(50) NOT NULL,
`XYZBatch` varchar(50) NOT NULL,
`BatchProcessedDate` date NOT NULL,
`ExpiryDate` date NOT NULL,
`Region` varchar(50) NOT NULL,
`FCCity` varchar(50) NOT NULL,
`VendorID` int(11) NOT NULL,
`LocationID` int(11) NOT NULL,
PRIMARY KEY (`CSN`),
KEY `ind_staging` (`SP`)
) ENGINE=InnoDB AUTO_INCREMENT=851956 DEFAULT CHARSET=latin1;