Results 1 to 3 of 3
  1. #1
    Join Date
    Sep 2014
    Posts
    1

    Unanswered: Left join with three tables

    I've three tables and trying to figure out the best way to query them for certain information.

    Here are the tables:

    users table
    uid, fname, lname

    users_groups table
    gid, uid

    users_facebook table
    uid, facebook_id

    I want query for all users (uid, fname, lname, facebook_id) for a given group.

    Some users may not have an entry in the users_facebook table.

    I have a sense that the left join is the way to go. However, I 'm not sure how to do left join when three tables are involved. In this case, we need to join users_groups and users tables and then do an left join with users_facebook table.

    What would be the best way to do it? My database has 100 K users. In terms of performance, would it make sense to split the query?

    Any help is appreciated.

  2. #2
    Join Date
    Feb 2008
    Location
    Japan
    Posts
    3,483
    ... However, I 'm not sure how to do left join when three tables are involved.
    First of all, you should know "how to do left join when three tables are involved",
    before going to
    ... and trying to figure out the best way to query them
    and
    What would be the best way to do it?
    (That may imply that you know some ways to get your desired result.)


    Anyhow,
    return to your question
    ... However, I 'm not sure how to do left join when three tables are involved.
    I want to recommend you to go to a solution, step by step, like...
    (1) make the join which you mentioned
    In this case, we need to join users_groups and users tables
    What query did you made to join users_groups and users tables?

    (2) Add an extra left join which was described in
    and then do an left join with users_facebook table
    for the query made in (1).

  3. #3
    Join Date
    Dec 2014
    Posts
    3
    Hi,

    You should try this:


    select users.uid, fname, lname, facebook_id, gid
    from users
    join users_groups
    on users.uid = users_groups.uid
    left join users_facebook
    on users.uid=users_facebook.uid
    order by gid

Tags for this Thread

Posting Permissions

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