Hello and welcome to our community! Is this your first visit?
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
    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 02:34 PM.

  2. #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Saskatoon, Saskatchewan
    Thanked 2,668 Times in 2,637 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.

  3. 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