Results 1 to 3 of 3
  1. #1
    Join Date
    May 2008
    Posts
    13

    Unanswered: query for many to many relationship

    I have two table called Products and Groups with Many to Many relationship. Some sample data:

    Product Id
    1
    2
    3
    4
    Group Ids
    10
    11
    12

    RelationShips

    GroupId ----> productId
    10 -----------> 1,2,3
    11 -----------> 2,4,3
    12 -----------> 3,5

    I will provide list of group Ids and i need Common products available in that group.
    for example :
    if i provide group id 11,12 i need common products as 3 as the result.
    if i provide group id 10,11,12 i need common products as 3 as the result.

    can this be achieved with a single query??
    I use Oracle 10g

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    okay, you have two tables, products and groups

    where are the relationships stored?

    if they stored as comma-delimited lists, you're already in trouble...
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  3. #3
    Join Date
    May 2008
    Posts
    13
    They are stored as primary foreign key relationship with group_id being primary key in Groups table and foreign key in Products table

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •