Results 1 to 6 of 6
  1. #1
    Join Date
    Oct 2003
    Posts
    33

    Unanswered: How can I find the matching table from a group of tables? (difficult to explain...)

    Let's say I have a list of IDs called EntryID and each EntryID can belong to ONE table out of a group of six, what is the best way to get a listing of these?

    For example:

    select r.*
    from #Reminders r
    left join mytable1 mt1 on (r.EntryID = mt1.EntryID)
    left join mytable2 mt2 on (r.EntryID = mt2.EntryID)
    left join mytable3 mt3 on (r.EntryID = mt3.EntryID)
    left join mytable4 mt4 on (r.EntryID = mt4.EntryID)

    As you can see, #Reminders has one field called EntryID (and many rows).

    In my example above, only ONE of those tables will actually be able to join but I have no idea which one has the matching EntryID.

    What is the best way for me to do this? I want to grab "ReportStatus" from the corresponding "mytable"... (each "mytable" has a ReportStatus column)

  2. #2
    Join Date
    Feb 2004
    Location
    One Flump in One Place
    Posts
    14,912
    How come these are distributed between 6 tables?
    Testimonial:
    pootle flump
    ur codings are working excelent.

  3. #3
    Join Date
    Oct 2003
    Posts
    33
    Because each table contains different information in addition to the common EntryID field...

  4. #4
    Join Date
    Feb 2004
    Location
    One Flump in One Place
    Posts
    14,912
    Ok. I will take your word that it is normalised properly.

    How many rows in #Reminders? Is there anyway of knowing which of the tables an id belongs to without actually looking in the tables (for example I worked somewhere where they split off the table into 8 tables based on the mod 8 +1 value of each ID)?
    Testimonial:
    pootle flump
    ur codings are working excelent.

  5. #5
    Join Date
    Feb 2004
    Location
    One Flump in One Place
    Posts
    14,912
    Actually - if there are 6 tables all with the same ID for different entities, do you not have a master table for common attributes which holds all the PKs? How do you enforce the requirement that an id can only appear in one of the six tables?
    Testimonial:
    pootle flump
    ur codings are working excelent.

  6. #6
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    Quote Originally Posted by pootle flump
    Ok. I will take your word that it is normalised properly.
    Daaaaaangerous!
    George
    Home | Blog

Posting Permissions

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