|
Performance semantics not withstanding, IMO the coolest way to solve this particular problem is by using bits. For those not quite sure how that would work, I suggest the following. A table with, among other columns, a column of type integer called "VoteBits". A separate table (VoteOptionMaster) with two columns; OptionID (Integer, PK) and OptionDesc (Not Null, varchar2). The VoteMaster table will contain the choices IDs and Descriptions (i.e. 1=Chocolate, 2=Vanilla, 4=Boxers, 8=Briefs, 16=Apples, 32=Oranges, etc). So, then say I voted for Chocolate, Boxers and Apples - I would save the value of 21 (or 1+4+16) in the VoteBits column. Then, you can use a bitwise operator in the query (I would probably write a function to return the associated description for each) to "detect" which bits are set. Since the numbers need to double for each vote choice, there is a limit to the number of choices you can have. I've used this successfully for just this purpose, but would only advise using if the number of possible choices is quite small.
|