I need help designing a SQL table. Suppose I have cardnumber, cardtype, field1, field2, and field3.
Cardtype is an enumeration that can be “front”, “back”, or “both”.
-
I want to SELECT front.field1, front.field2, front.field3, back.field1, back.field2, back.field3 FROM some table or view WHERE cardnumber=XXX.
-
Most of the records will just contain field1, field2, field3, and “both” indicating that I should get front.field1 to be the same as back.field1, etc… when I SELECT. When “front” and “back” are different, I will need two rows with the same cardnumber, but one with “front” and the other with “back”, along with the appropriate field1…field3 for each side.
How do I design this table. Should I be using some VIEW of an INNER JOIN or a LEFT/RIGHT JOIN of some sort?
I’m open to different designs but I am hoping that any design will be easy to maintain (taking into account that most records will be one row containing “both”) and can satisfy my SELECT requirement.
1 Answer