Results 1 to 4 of 4
  1. #1
    Join Date
    Oct 2010
    Location
    Atlanta, GA
    Posts
    211
    Provided Answers: 1

    Question Unanswered: Conditional Joining?

    I have two tables that are joined via a LEFT join so I see all the records in table 1 and only those in table 2 where the joined field (SeqNum) match. SeqNum may be null in Table 1. Everything is working fine. But now I need to do the join, but conditionally, sort of. Let me explain:

    I want it to continue to show all records from Table one, and if SeqNum is not null in table 1, then join on SeqNum AND WorkOrder. As oyu can see, the issue is thgat SeqNum can be null, so i can't just join on WorkOrder in a previous query and then do the LEFT join. Ideas?

    I got very little sleep last night so it is possible my brain is just not working this morning.

  2. #2
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    Use a WHERE expression in place of a LEFT JOIN.
    Have a nice day!

  3. #3
    Join Date
    Oct 2010
    Location
    Atlanta, GA
    Posts
    211
    Provided Answers: 1
    Quote Originally Posted by Sinndho View Post
    Use a WHERE expression in place of a LEFT JOIN.
    I am struggling with visualizing this. Can you help with an example? Thank you.

  4. #4
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    If I correctly understand what you try to achieve (not sure I am), it would be something like:
    Code:
    SELECT Tbl_CF_DATA.*, Tbl_LCF_Data.*
      FROM Tbl_CF_DATA LEFT JOIN Tbl_LCF_Data ON 
          (Tbl_CF_DATA.WorkOrder = Tbl_LCF_Data.WorkOrder) AND 
          (Tbl_CF_DATA.SeqNum = Tbl_LCF_Data.SeqNum)
    WHERE (Tbl_CF_DATA.SeqNum Is Not Null);
    Have a nice day!

Posting Permissions

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