Help needed with unique key (MYSQL)

Help needed with unique key (MYSQL)

here is a a description of my database id,col1,col2.

what i want to do is have unique key from col1,col2.
which means that if there is a record such as

id=1 , col1=1 , col2=2

there can’t be a record such as

id=5 , col1= 2 , col2=1.

I have tried creating two indexes such as

index1:col1,col2 unique


index2:col2,col1 unique but these only keeps out from inserting
again id=1 , col1=1 , col2=2

In other word the unique key must check the combinations.
I am using mysql.

a unique key cannot check both combinations

this sounds like a “col1 is friends with col2” application, and it sounds like the relationship is bi-directional, i.e. if fred is friends with mary then mary is friends with fred, and you don’t want both fred-mary and mary-fred combinations in the database

simple solution: change your application code so that it only ever stores a col1-col2 combination where col1 is always less than col2

thanks , that was what I had in mind