Unique combination?

Hey,

Is it possible to have a unique combination of two data types?

For example

table_a:

id - id1 - id2

1 - 100 - 264

user id 1 and user id 2 will always be unique to each other. No other row can contain 264 - 100, vice versa.

any help :slight_smile:

declare a compound UNIQUE constraint on (id1,id2)

if this is mysql, then, in your application logic, make sure you always insert ~only~ where id1 < id2, never the other way around

if this isn’t mysql, you can add a CHECK constraint for ( id1 < id2 )

got it, thanks.