I'm creating my first SQLite database in a C# program. The program is related to poker/playing cards. I have a table called Flop defined as follows:
CREATE TABLE Flop
(
id SMALLINT UNIQUE NOT NULL,
card1 TINYINT NOT NULL,
card2 TINYINT NOT NULL,
card3 TINYINT NOT NULL,
CONSTRAINT Flop_pk PRIMARY KEY (card1, card2, card3)
);
Flop
contains the id of 3 playing cards from a 52 card deck and I want to avoid duplicate Flop rows where the 3 cards match but are in a different order. If my card ids are 1,2,3 I wish to prevent adding an entry for a Flop of 2,3,1 or 1,3,2 etc. How do I set up my key constraints so that the card order is ignored?
Also, how can I select a flop given that my 3 cards passed into the SELECT
statement may be in any order? I assume there must be a more simple way than checking all 6 combos like:
SELECT id FROM Flop WHERE (card1 = 1 AND card2 = 2 AND card3 = 3)
OR (card1 = 3 AND card2 = 1 AND card3 = 2)
OR (card1 = 2 AND card2 = 3 AND card3 = 1)
OR (card1 = 1 AND card2 = 3 AND card3 = 2)
OR (card1 = 2 AND card2 = 1 AND card3 = 3)
OR (card1 = 3 AND card2 = 2 AND card3 = 1);