Rocco The Taco
Rocco The Taco

Reputation: 3777

MySQL insert ignore in PHP with where statement?

I have the following MySQL statement in a PHP file that imports a .csv file. The statement successfully ignores exact record matches but I am getting some duplicate records in the table where the records are not exact 100%. I did notice that in those cases where duplicates are occuring the LATITUDE and LONGITUDE is still always the same. Is there a way to expand this with some sort of WHERE statement to also exclude records on import if these two fields already have a match in the table? I've tried all sorts of WHERE attempts and get a MySQL error?

    $query = "insert ignore into $databasetable values('$linemysql');";

Upvotes: 1

Views: 188

Answers (1)

jeroen
jeroen

Reputation: 91734

You can add a unique index on multiple columns in mysql directly.

In mysql it would be something like (for 2 columns from memory...):

ALTER TABLE `your_table` ADD UNIQUE `some_name_like_position` ( `LATITUDE` , `LONGITUDE` );

Upvotes: 1

Related Questions