Results 1 to 10 of 10
  1. #1
    svcghost is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Sep 2010
    Posts
    38

    joining on two userid's

    Hello. I have two tables: users and actions
    One action contains two users so there are two primary keys user1id and user2id (which are foreign keys from the users table)

    How would I go about joining these tables in a query where I want to select each of the users' last names? The last names are a field in the users table.

    Example query:
    Code:
    SELECT users.lastname
    FROM (actions LEFT JOIN users ON actions.user1id = users.userid) 
    LEFT JOIN users ON actions.user2id = users.userid
    This does not work however.

    All help is greatly appreciated


    I write sql directly, no wizard stuff.
    Last edited by svcghost; 09-26-2010 at 09:39 PM.

  2. #2
    HiTechCoach's Avatar
    HiTechCoach is offline MS MVP - Access Expert
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Jul 2010
    Location
    Oklahoma, USA
    Posts
    702
    I would recommend that you use the query designer view.

    Add the actions table and the users table twice. The second copy will be named
    users_1.

    Now you can make your two joins.

  3. #3
    svcghost is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Sep 2010
    Posts
    38
    Coach, thank you so much! Worked just perfectly.

  4. #4
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Quote Originally Posted by svcghost View Post
    Coach, thank you so much! Worked just perfectly.
    Are you ready to follow the link in my sig and mark this thread as Solved?

  5. #5
    HiTechCoach's Avatar
    HiTechCoach is offline MS MVP - Access Expert
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Jul 2010
    Location
    Oklahoma, USA
    Posts
    702
    Quote Originally Posted by svcghost View Post
    Coach, thank you so much! Worked just perfectly.
    You're welcome!

    Glad that worked for you.

    Please mark this as solved.

  6. #6
    svcghost is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Sep 2010
    Posts
    38
    Quote Originally Posted by RuralGuy View Post
    Are you ready to follow the link in my sig and mark this thread as Solved?
    done. thanks.

  7. #7
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Thank you and did you give Boyd a point or two?

  8. #8
    svcghost is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Sep 2010
    Posts
    38
    I added to his reputation, approved. If that's what you meant?

  9. #9
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Quote Originally Posted by svcghost View Post
    I added to his reputation, approved. If that's what you meant?
    That's what I meant and I know Boyd deserves it. Thanks.

  10. #10
    HiTechCoach's Avatar
    HiTechCoach is offline MS MVP - Access Expert
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Jul 2010
    Location
    Oklahoma, USA
    Posts
    702
    Thank you svcghost and RuralGuy!

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

Similar Threads

  1. Joining a Query
    By access_gbr in forum Queries
    Replies: 1
    Last Post: 05-04-2010, 10:46 AM
  2. Joining multiple categories.
    By Bmo in forum Queries
    Replies: 1
    Last Post: 04-18-2010, 10:00 AM
  3. Joining or Combining Two tables
    By escuro19 in forum Queries
    Replies: 2
    Last Post: 02-16-2010, 03:55 PM
  4. Joining Unioins output to tables? Help Needed
    By techexpressinc in forum Queries
    Replies: 4
    Last Post: 06-24-2009, 05:05 PM
  5. Joining tables two tables and another table that is not
    By DevintheDude in forum Database Design
    Replies: 0
    Last Post: 09-12-2007, 08:56 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