Results 1 to 4 of 4
  1. #1
    younggunnaz69 is offline Novice
    Windows Vista Access 2007
    Join Date
    Apr 2011
    Posts
    7

    Using a hierarchy table

    I have two tables like below and I'm trying to create a query to combine the two. Examples are below. I tried to search but could not find any help. Thanks for your help.



    tbl_hierarchy
    Store_Num RM_ID GM_ID M_ID
    1 E111 E223 E323
    2 E111 E224 E324
    3 E112 E225 E325
    4 E112 E226 E326









    tbl_emp
    E_ID FName
    E111 Tom
    E112 Bob
    E223 Jim
    E224 Sam
    E226 Sarah
    E323 Ann
    E324 Marie
    E325 Kelly
    E326 Connie

    Result-

    Store_Num RM_ID RM_Name GM_ID GM_Name M_ID M_Name
    1 E111 Tom E223 Jim E323 Ann
    2 E111 Tom E224 Sam E324 Marie
    3 E112 Bob E225 E325 Kelly
    4 E112 Bob E226 Sarah E326 Connie

  2. #2
    recyan's Avatar
    recyan is offline Expert
    Windows 2K Access 2000
    Join Date
    Dec 2011
    Posts
    662
    Just check out if below gives some guidelines :
    Code:
    SELECT 
        tbl_hierarchy.Store_Num, 
        tbl_hierarchy.RM_ID, 
        tbl_emp.E_ID, 
        tbl_emp.FName, 
        tbl_hierarchy.GM_ID, 
        tbl_emp_1.E_ID, 
        tbl_emp_1.FName, 
        tbl_hierarchy.M_ID, 
        tbl_emp_2.E_ID, 
        tbl_emp_2.FName
    FROM 
        (
            (
                tbl_hierarchy 
                LEFT JOIN 
                tbl_emp 
                ON 
                tbl_hierarchy.RM_ID = tbl_emp.E_ID
            ) 
            LEFT JOIN 
            tbl_emp AS tbl_emp_1 
            ON 
            tbl_hierarchy.GM_ID = tbl_emp_1.E_ID
        ) 
        LEFT JOIN 
        tbl_emp AS tbl_emp_2 
        ON 
        tbl_hierarchy.M_ID = tbl_emp_2.E_ID;
    Thanks

  3. #3
    younggunnaz69 is offline Novice
    Windows Vista Access 2007
    Join Date
    Apr 2011
    Posts
    7
    Thanks it worked fine. I deleted the   in the join statments. I wasnt sure what they were for?? But other than that it worked fine. Thanks again!!

  4. #4
    recyan's Avatar
    recyan is offline Expert
    Windows 2K Access 2000
    Join Date
    Dec 2011
    Posts
    662
    Quote Originally Posted by younggunnaz69 View Post
    I deleted the   in the join statments. I wasnt sure what they were for??
    It is not supposed to be there. Guess some formatting issue.
    Quote Originally Posted by younggunnaz69 View Post
    Thanks it worked fine.
    Glad, you found it helpful.

    Thanks

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

Similar Threads

  1. Tree hierarchy of Parts [Complex]
    By xAkademiks in forum Programming
    Replies: 5
    Last Post: 07-01-2012, 02:58 AM
  2. Hierarchy summing
    By dskysmine in forum Queries
    Replies: 17
    Last Post: 06-19-2012, 04:08 AM
  3. product hierarchy
    By Lata in forum Access
    Replies: 13
    Last Post: 08-03-2011, 02:56 AM
  4. Replies: 1
    Last Post: 02-05-2010, 08:33 AM
  5. Replies: 2
    Last Post: 10-27-2009, 07:09 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