wood burning stoves 2.0*
The moose likes JDBC and the fly likes How to make list of foreign keys (intermediate SQL question) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Databases » JDBC
Bookmark "How to make list of foreign keys (intermediate SQL question)" Watch "How to make list of foreign keys (intermediate SQL question)" New topic
Author

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

Russell Bateman
Ranch Hand

Joined: Feb 26, 2008
Posts: 69
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

Joined: May 26, 2003
Posts: 30595
    
154

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.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Russell Bateman
Ranch Hand

Joined: Feb 26, 2008
Posts: 69
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
 
GeeCON Prague 2014
 
subject: How to make list of foreign keys (intermediate SQL question)