Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Sep 2012
    Posts
    76
    Thanks
    61
    Thanked 0 Times in 0 Posts

    Join where there is sometimes no value?

    Hello, I am after some help please. I have two tables, which I wish to query to output all the records in table_a.

    - In table_a I have a field named 'thecategoryid'
    - In table_b I have a field named 'categoryid'

    But my problem is in table_a 'thecategoryid' field in each row can sometimes contain a value and sometimes not, so I can't join like so

    table_a.thecategoryid = table_b.catgoryid

    So how can I output all records in table_a with a join on table_b but with it not mattering if there is or there is not a value on the row 'thecategoryid'

    Is this possible?

    Thank you
    Last edited by Oatley; 12-14-2012 at 03:34 PM.

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    Sure you can. Just use a LEFT JOIN to fetch all records from the primary table (governed by the where clause of course), and any matching records from the child table.

  • Users who have thanked Fou-Lu for this post:

    Oatley (12-14-2012)


  •  

    Posting Permissions

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