If you have two DIFFERENT records with the same Product column, you can select unwanted records with some criteria, for example.
CREATE TABLE victims AS
SELECT MAX(entryDate) AS date, Product, COUNT(*) AS dups FROM ProductsTable WHERE ...
GROUP BY Product HAVING dups > 1;
Then you can do DELETE JOIN between ProductTable and victims.
, DELETE - JOIN, , CustomerId NULL EntryDate - . , , , .
, ( , - , , ). . SELECT ProductsTable SELECT DISTINCT , , , ( , . MAX MIN). "" .
DELETE JOIN . reimport .
, DELETE JOIN INSERT SELECT , .
, MySQL:
CREATE TABLE deduped AS SELECT * FROM ProductsTable WHERE false;
CREATE UNIQUE INDEX deduped_ndx ON deduped(Product);
INSERT IGNORE INTO deduped SELECT * FROM ProductsTable;
ALTER TABLE ProductsTable RENAME TO ProductsBackup;
ALTER TABLE deduped RENAME TO ProductsTable;
: , " " " ". , DUPLICATE, , !
:
, "" . :
SELECT * FROM ProductsTable ORDER BY Product, FieldWhichShouldNotBeNULL IS NULL;
, , , . , , (FieldWhichShouldNeverBeNull IS NULL) FALSE ( , FieldWhichShouldNeverBeNull , ), . , - IGNORE, . ( , true false !), .
,
CREATE TABLE ProductTable ( Product varchar(10), Description varchar(10) );
INSERT INTO ProductTable VALUES ( 'CBPD10', 'C-Beam Prj' );
INSERT INTO ProductTable VALUES ( 'CBPD11', 'C Proj Mk2' );
INSERT INTO ProductTable VALUES ( 'CBPD12', 'C Proj Mk3' );
. .
- . , NULL.
, , CBPD14 , . CBPD10.
INSERT INTO ProductTable VALUES ( 'CBPD10', NULL );
INSERT INTO ProductTable VALUES ( 'CBPD14', NULL );
ProductTable WHERE IS NULL , CBPD14, .
, . :
SELECT Product, COUNT(*) AS Dups FROM ProductTable GROUP BY Product HAVING Dups > 1;
, : " ".
, . , , .
SELECT Dups.Product FROM ProductTable
RIGHT JOIN ( SELECT Product, COUNT(*) AS Dups FROM ProductTable GROUP BY Product HAVING Dups > 1 ) AS Dups
ON (ProductTable.Product = Dups.Product
AND ProductTable.Description IS NOT NULL)
WHERE ProductTable.Description IS NULL;
, , ; , .
INSERT INTO ProductTable VALUES ( "AC5", NULL ), ( "AC5", NULL );
"check" ,
AC5
, Dups .
, . , , , - , "" "" (, , ).
, . (http://dev.mysql.com/doc/refman/5.0/en/delete.html). :
CREATE TEMPORARY TABLE Dups AS
SELECT Product, COUNT(*) AS Duplicates
FROM ProductTable GROUP BY Product HAVING Duplicates > 1;
DELETE ProductTable FROM ProductTable JOIN Dups USING (Product)
WHERE Description IS NULL;
, , Dups.
CBPD14 , . "" CBPD10 , , NULL. - .
, , , - .
, , SELECT ( , ", " ) , , , ( ).