I don’t mean two exactly same rows.
My table’s simple structure is something like this:
id val1 val2
val1 and val2 are used to link two objects together, and I can’t know which is which because they reference the same table.
I need to avoid the following:
id val1 val2 1 40 60 2 60 40
I can use INSERT IGNORE to avoid direct duplicates, but it doesn’t work with the one above.
I’m also trying to avoid multiple queries from PHP, so I’m asking if it is possible to do this in one SQL query that is sent from PHP.
When inserting, just check if
val1 <= val2, if so insert them in that order, if not switch them. With this condition you will always be sure that duplicate values result in identical inserts.