Results 1 to 6 of 6
  1. #1
    e.badin is offline Novice
    Windows XP Access 2003
    Join Date
    Jan 2011
    Posts
    16

    Angry Left join problem

    Hi guys,

    What the hell am I doing wrong ? This is really pissing me off. As simple as it may be, it got me realy frustrated because it doesn't work proper.

    So...I have this 2 tables A,B. The combination Resource id / Cost account is the primary key. What I need is to get all the values from A and add the C column from B, where is the case.

    Table A
    --------------------------


    Resource Id | Cost Account

    Table B
    ---------------------------------
    Resource ID | Cost Account | C

    The query should be this:

    Code:
    SELECT A.*, B.C
    FROM A LEFT JOIN B ON (A.[Cost Account] = B.[Cost Account]) AND (A.[Resource ID] = B.[Resource ID]);
    The problem is that I get nothing in the C column for the combination Resource ID | Cost Account, when Cost Account is Null, even if in the B table there is data.

    Please tell me I'm stupid I don't know how to use the Left Join....

    Edit:
    I checked the previous topics with null related issues but I still have trouble understand the outcome of the those disscusions.

  2. #2
    Rixxe is offline Blessed Bear
    Windows 7 Access 2007
    Join Date
    Sep 2010
    Location
    London (Essex ... yep!)
    Posts
    184
    Code:
     
    SELECT a.*
    FROM TableA as A
    LEFT JOIN 
    TableB as B
    ON(A.[Cost Account] = B.[Cost Account]) AND (A.[Resource ID] = B.[Resource ID])
    WHERE b.[Cost Account] is null
    I'm sure you need a "WHERE [Field] is null" somewhere in a left join...

  3. #3
    weekend00 is offline I may not be right
    Windows XP Access 2003
    Join Date
    Aug 2010
    Posts
    1,295
    null doesn't match null in a join query, just like null=null is false in expression;

    that means you can not get result when the join field is null.

    you can try to change the query to:
    SELECT A.*, B.C FROM A LEFT JOIN B ON (nz(A.[Cost Account],"") = nz(B.[Cost Account],"")) AND (nz(A.[Resource ID],"") = nz(B.[Resource ID],""));


    To Rixxie:
    you query with where clause is to get the records only exist in tableA but not exist in tableB, this is not the OP wants.

  4. #4
    e.badin is offline Novice
    Windows XP Access 2003
    Join Date
    Jan 2011
    Posts
    16
    thanks... I changed the null tu "NA".... but I still can't understand why null<>null...

  5. #5
    weekend00 is offline I may not be right
    Windows XP Access 2003
    Join Date
    Aug 2010
    Posts
    1,295
    null=null is false while null<>null is also false, you should not compare with null, 'cause null is nothing, you can not compare nothing. how can you compare when there is nothing?

  6. #6
    Rixxe is offline Blessed Bear
    Windows 7 Access 2007
    Join Date
    Sep 2010
    Location
    London (Essex ... yep!)
    Posts
    184
    Misread on my part, Thanks weekend.

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

Similar Threads

  1. Outer left join leaves out null values
    By mschles4695 in forum Queries
    Replies: 1
    Last Post: 12-22-2010, 11:43 PM
  2. LEFT JOIN Breaks with Where Clause
    By jascraig in forum Queries
    Replies: 3
    Last Post: 08-31-2010, 08:56 AM
  3. Problem with Left Join & VB6
    By msrdjan1 in forum Queries
    Replies: 0
    Last Post: 03-30-2010, 01:48 AM
  4. Error using left join accessing 2 active connections
    By peterg2000 in forum Programming
    Replies: 0
    Last Post: 10-05-2009, 05:04 PM
  5. Update with LEFT JOIN
    By mcarthey in forum Access
    Replies: 1
    Last Post: 08-27-2008, 10:49 AM

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
  •  
Other Forums: Microsoft Office Forums