developarvin
developarvin

Reputation: 5087

Duplicate column combination in MySQL

Sample Table

first_column     second_column
1                   2

In the sample table above, is there a way to make a constraint in MySQL so that inserting (2,1) would return duplicate key error?

Upvotes: 0

Views: 158

Answers (2)

Novikov
Novikov

Reputation: 4489

When dealing with these kind of "pairings" I try to insert in order. Like

INSERT INTO blah (one, two) VALUES (?, ?)
params += min(one, two)
params += max(one, two)

Of course this doesn't answer your question of how to set a constraint.

Upvotes: 2

Dan Grossman
Dan Grossman

Reputation: 52372

No. (2,1) is not the same tuple as (1,2).

Upvotes: 1

Related Questions