Results 1 to 10 of 10
  1. #1
    cheechootrain is offline Novice
    Windows 8 Access 2010 32bit
    Join Date
    Apr 2013
    Posts
    19

    Show Multiple Tables in Query

    Hello,



    I was wondering if anyone knows how to show multiple tables in one query without duplications. I've attached a mock database of what I am working on. Basically, I want to show all of the numbers from different tables regarding one patient. But when I do using the Patient ID, it repeats the information over and over again. Is this the right way? Or is there a better way? I know I can use forms, but I ultimately want to transfer this database to excel so I can use graphs to describe the trends of the patients' results. My real database has about 300 columns, for all 5 tables.

    Thanks for your help!

    Cheechoo
    Attached Files Attached Files

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,621
    300 columns!?!? Tables have a limit of 256 fields. It's rare to see them all used. Often an indication of non-normalized data structure.

    "Duplication" will happen when joining 'master' (or parent) table to multiple 'child' tables (child tables have many records associated with master). Better to do a report with subreports for each of the related child tables.

    Or can do aggregate query on each of the child tables and then join the queries to master.

    Your sample tables have only one record for each patient. This should not result in "duplication".

    SELECT Patients.*, [Lung Volumes].*, PH.*, CT.*
    FROM [Lung Volumes] RIGHT JOIN (CT RIGHT JOIN (Patients LEFT JOIN PH ON Patients.[Patient ID] = PH.[Patient ID]) ON CT.[Patient ID] = Patients.[Patient ID]) ON [Lung Volumes].[Patient ID] = Patients.[Patient ID];

    PatientID fields in CT and LungVolumes should be changed to number type to match the PatientID primary key in Patients.

    Advise no spaces or special characters/punctuation (underscore is exception) in names nor reserved words as names. Better would be PatientID or Patient_ID.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    cheechootrain is offline Novice
    Windows 8 Access 2010 32bit
    Join Date
    Apr 2013
    Posts
    19
    Quote Originally Posted by June7 View Post
    300 columns!?!? Tables have a limit of 256 fields. It's rare to see them all used. Often an indication of non-normalized data structure.

    "Duplication" will happen when joining 'master' (or parent) table to multiple 'child' tables (child tables have many records associated with master). Better to do a report with subreports for each of the related child tables.

    Or can do aggregate query on each of the child tables and then join the queries to master.

    Your sample tables have only one record for each patient. This should not result in "duplication".

    SELECT Patients.*, [Lung Volumes].*, PH.*, CT.*
    FROM [Lung Volumes] RIGHT JOIN (CT RIGHT JOIN (Patients LEFT JOIN PH ON Patients.[Patient ID] = PH.[Patient ID]) ON CT.[Patient ID] = Patients.[Patient ID]) ON [Lung Volumes].[Patient ID] = Patients.[Patient ID];

    PatientID fields in CT and LungVolumes should be changed to number type.

    Advise no spaces or special characters/punctuation in names nor reserved words as names. Better would be PatientID or Patient_ID.
    Haha, I mean I have almost total of 300. So maybe 80 to 90 per table.

    Yeah, I tried using report. But I do like the query idea. Thanks!!

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,621
    That's still a lot of fields but more reasonable. You did not provide that structure for analysis.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    KathyL is offline Advanced Beginner
    Windows 7 Access 2007
    Join Date
    Aug 2010
    Posts
    94
    You’re more likely going to transfer only a table or query result to excel for a graph, not the entire database.
    Joining a parent table to a child table will always show the repetition of information, as you do have a one-to-many relationship. Think about it, how else could you show the data in a datasheet where you match on a one-to-many relationship? One side will have to show it’s data repeated.
    But if you take that query to a report, you can tell the report to suppress printing of the duplicates.

  6. #6
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,621
    Kathy, I think user is including several 'many' side tables in the join so the duplication is beyond just repetition of the parent info.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  7. #7
    KathyL is offline Advanced Beginner
    Windows 7 Access 2007
    Join Date
    Aug 2010
    Posts
    94
    "Kathy, I think user is including several 'many' side tables in the join so the duplication is beyond just repetition of the parent info."

    Yikes. I might then tell the original OP... you can't join many-to-many tables, not directly. Somewhere in the mix, it will need a parent table for one-to-many links.

  8. #8
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,621
    That's the issue. They are joining several 'many' side child tables to the 'one' side parent. Post 2 explains that doesn't work nice.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  9. #9
    cheechootrain is offline Novice
    Windows 8 Access 2010 32bit
    Join Date
    Apr 2013
    Posts
    19
    You're both right. I just did a report to print off data for one patient. For graphing, I ran a separate query for each table and exported individually to excel and did copy and paste.

    Thanks for the help!

  10. #10
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,621
    Access graphing was not adequate for your needs? I have many graphs in forms and reports.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 1
    Last Post: 04-12-2013, 03:03 PM
  2. Replies: 7
    Last Post: 12-30-2012, 03:59 AM
  3. Replies: 3
    Last Post: 04-11-2012, 08:21 AM
  4. Replies: 3
    Last Post: 01-05-2012, 12:04 PM
  5. Replies: 2
    Last Post: 11-05-2010, 04:47 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums