This sequence of queries will remove data that has been accidentally registered multiple times into rawExp & rawImfile.

<pre> CREATE TEMPORARY TABLE rawExp_tmp (exp_id BIGINT, exp_name VARCHAR(64), camera VARCHAR(64), telescope VARCHAR(64), dateobs DATETIME, exp_tag VARCHAR(255), exp_type VARCHAR(64), filelevel VARCHAR(64), workdir VARCHAR(255), reduction VARCHAR(64), dvodb VARCHAR(255), tess_id VARCHAR(64), end_stage VARCHAR(64), filter VARCHAR(64), comment VARCHAR(80), airmass FLOAT, ra DOUBLE, decl DOUBLE, exp_time FLOAT, sat_pixel_frac FLOAT, bg DOUBLE, bg_stdev DOUBLE, bg_mean_stdev DOUBLE, alt DOUBLE, az DOUBLE, ccd_temp FLOAT, posang DOUBLE, m1_x FLOAT, m1_y FLOAT, m1_z FLOAT, m1_tip FLOAT, m1_tilt FLOAT, m2_x FLOAT, m2_y FLOAT, m2_z FLOAT, m2_tip FLOAT, m2_tilt FLOAT, env_temperature FLOAT, env_humidity FLOAT, env_wind_speed FLOAT, env_wind_dir FLOAT, teltemp_m1 FLOAT, teltemp_m1cell FLOAT, teltemp_m2 FLOAT, teltemp_spider FLOAT, teltemp_truss FLOAT, teltemp_extra FLOAT, pon_time FLOAT, user_1 DOUBLE, user_2 DOUBLE, user_3 DOUBLE, user_4 DOUBLE, user_5 DOUBLE, object VARCHAR(64), solang FLOAT, fault SMALLINT NOT NULL, KEY(exp_id), PRIMARY KEY(exp_name, camera, telescope), KEY(end_stage), KEY(fault), FOREIGN KEY (exp_id) REFERENCES newExp(exp_id)) ENGINE=MYISAM;

INSERT IGNORE into rawExp_tmp SELECT * FROM rawExp;

SET FOREIGN_KEY_CHECKS=0;

DELETE FROM newExp WHERE exp_id = ANY(SELECT exp_id FROM rawExp LEFT JOIN rawExp_tmp USING(exp_id) WHERE rawExp_tmp.exp_id IS NULL); DELETE FROM newImfile WHERE exp_id = ANY(SELECT exp_id FROM rawExp LEFT JOIN rawExp_tmp USING(exp_id) WHERE rawExp_tmp.exp_id IS NULL); DELETE FROM rawImfile WHERE exp_id = ANY(SELECT exp_id FROM rawExp LEFT JOIN rawExp_tmp USING(exp_id) WHERE rawExp_tmp.exp_id IS NULL);

TRUNCATE rawExp;

INSERT INTO rawExp SELECT * FROM rawExp_tmp;

SET FOREIGN_KEY_CHECKS=1; </pre>