Cookie Notice

As far as I know, and as far as I remember, nothing in this page does anything with Cookies.

2012/02/09

Thinking Aloud on an SQL Problem

This is an extension of this question from StackOverflow. I have a pile of Xs, each with an id. Some are allowed to be together, and I want a table to hold them. But...
  • I want to be able to group pairs and triads
  • I want a simple interface
StackOverflow users pointed me in the right direction, which is to an idea I had seen before. The table for X could look like this:

 id | string 
----+--------
 01 | aaabbb
 02 | aabbaa
 03 | bbaabb
 04 | bbbaaa
 05 | aaaaaa
 06 | bbbbbb
 07 | bababa
 08 | abbaab

While a grouping table could look like this:

 group_id | x_id 
----------+--------
 01       | 01
 01       | 02
 02       | 01
 02       | 04
 02       | 06

That looks fine enough, except there is no indication as to how many x_ids are allowed in any given group_id. I was thinking/hoping/praying-to-the-computing-gods that only two tables would be necessary, but I'm thinking I will have to make a third:

 
 id  | size 
-----+--------
 01  | 2
 02  | 3

So, that's the decision. I need to have a third table.

No comments:

Post a Comment