I want to store if two events are combinables. It's a n to n relation, so I need to have a pivot table with these constraints :
I tried to create my table with this query :
event_id_1 INT UNSIGNED, event_id_2 INT UNSIGNED, cumulative_place INT, PRIMARY KEY(event_id_1,event_id_2), FOREIGN KEY(event_id_1) REFERENCES events(id) ON DELETE CASCADE, FOREIGN KEY(event_id_2) REFERENCES events(id) ON DELETE CASCADE );
Following MySQL Documentation
I have some questions about that :
Sort the pair.
INSERT ... VALUES ( LEAST("e1", "e2"), GREATEST("e1", "e2"), ...)
Similarly, sort the pair when doing a lookup. That way you have 1 row, not 2, and you don't have to look for both orders.
2.1m questions
2.1m answers
60 comments
57.0k users