• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
reply
    Bookmark Topic Watch Topic
  • New Topic