SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Thread: Left Join?

  1. #1
    SitePoint Evangelist
    Join Date
    Nov 2004
    Location
    sweden
    Posts
    564
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Left Join?

    I really don't get this LEFT JOIN. Can someone explain this pretty easy?

    Let's say I have 2 tables.
    Table A: a_id, name, info
    Table B: b_id, title, a_no

    In table A I have everything complete and in table B I only have some people from Table A
    that are linked (via a_no -> a_id).

    Let's say in A I have:
    1, james, a good friend
    2, sean, likes coffee
    3, linda, vegetarian

    And in Table B I have:
    1, teacher, 1
    2, nurse, 3

    As you can see all 3 friends in table a need to be listed and Sean (No 2) is not linked to Table B,
    but I need him listed as well.

    So, now I want a list of all my friends in Table A (even if they don't have been added to Table B).
    I think the correct way is to use JOIN LEFT, but in what way?

    Can someone explain this by using this easy example. Then I hope I will understand how it works.


  2. #2
    SitePoint Enthusiast
    Join Date
    Mar 2004
    Location
    Ukraine, Khmelnitsky
    Posts
    55
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    SELECT /* what */
    FROM tbl_A LEFT JOIN tbl_B
    ON tbl_A.a_id = tbl_B.a_no
    Sergey Bres aka tserbis, Ukraine

Bookmarks

Posting Permissions

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