Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to make list of foreign keys (intermediate SQL question)

 
Russell Bateman
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I need to create a table of subscribers to a service. At sign-up, the subscriber will choose a number of schools whose sports teams interest him or her. As there may be 1 or more, I need an SQL table construct to simulate what would be an Array or List of indeterminate length in Java or C. I'm just inexperienced enough in SQL not to know how to do this.



I would be very grateful if someone put me on the right track to using an intermediate table (that I can't think how to construct) or any other solution that can solve this problem that I can only assume is a trivial arrow in the quiver of genuine SQL guys.

Thanks.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34401
346
Eclipse IDE Java VI Editor
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It sounds like you are trying to map a many to many relationship.

One way to do this is to create an intermediate relationship table with school_id and (subscriber) id columns. Then you can do a join with the other tables to get the school name/address and subscriber info that goes with each school.
 
Russell Bateman
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ah, good. I'm glad I recognize both the terminology (many-to-many) and can conceive the solution based on your brief explanation. Thank you very much for awakening my brain!

Best regards,

Russ
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic