1

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');";

1 Answer 1

1

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` );
Sign up to request clarification or add additional context in comments.

3 Comments

So if I set a primary key on MLS_LISTING_ID, LATITUDE and LONGITUDE for example must all 3 match for a record to be omitted? Is it possible to omit if MLS_LISTING_ID OR (LATITUDE and LONGITUDE) matches?
@Rocco The Taco Yes, the combination of the 3 is defined as unique so you cannot add a new row with the exact same 3 values but 2 the same ones and 1 different one will enter.
Excellent. That was my problem, I did not account that the MLS could be different. I set MLS as the primary and then created an index for Lat/Long and it worked. Thanks so much for the help!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.