Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8443715
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T09:12:46+00:00 2026-06-10T09:12:46+00:00

Hello i have a problem joining tables when i have null values in a

  • 0

Hello i have a problem joining tables when i have null values in a record.

There are 2 dataTables:

  1. Workers: (workerID, workerName, workerAdress)
  2. Transactions: (transactionID, transactioinValue, worker1, worker2), where worker 2 is optional so it can contain null values.

So i started code like this:

var record = from transaction in dtTransactions.AsEnumerable()
    join worker1 in dtWorkers.AsEnumerable() on (int)transactions["worker1"] equals (int)worker1["workerID"]
    join worker2 in dtWorkers.AsEnumerable() on (int)transactions["worker2"] equals (int)worker2["workerID"]
    select new
    {
     ID = (int)transactions["transactionID"],
     Name1= worker1["workerName"],
     Name2= worker2["workerName"]
    };

So it all works fine if worker2 isn’t null, but when i have a null value it could not be joined. Can someone help me with this problem, i would like to have a result record without a worker2 name if it’s null in dataTable.

Is it possible?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T09:12:48+00:00Added an answer on June 10, 2026 at 9:12 am

    you need to do a left join like this;

    var record = from transaction in dtTransactions.AsEnumerable()
                         join worker1 in dtWorkers.AsEnumerable() on (int)transactions["worker1"] equals (int)worker1["workerID"]
                         join worker2 in dtWorkers.AsEnumerable() on (int)transactions["worker2"] equals (int)worker2["workerID"] into w2
                         from wrk in w2.DefaultIfEmpty()
                         select new
                         {
                             ID = (int)transactions["transactionID"],
                             Name1= worker1["workerName"],
                             Name2= wrk["workerName"]
                         };
    

    Secondly, is there any reason why you’re not specifying the object properties like this;

                    var record = from transaction in dtTransactions.AsEnumerable()
                     join worker1 in dtWorkers.AsEnumerable() on (int)transactions.worker1 equals (int)worker1.workerID
                     join worker2 in dtWorkers.AsEnumerable() on (int)transactions.worker2 equals (int)worker2.workerID into w2
                     from wrk in w2.DefaultIfEmpty()
                     select new
                     {
                         ID = (int)transactions.transactionID,
                         Name1= worker1.workerName,
                         Name2= wrk != null ? wrk.workerName : ""
                     };
    

    Note the removal of the square brackets

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hello i have the following problem, I record a video using red5 like this:
Hello I have a problem with GregorianCalendar. What is wrong in there? How outcome
Hello I have a little problem with assigning property values from one lists items
Hello I have problem to put together animations of two separate objects to second
Hello I have a problem with trimming string in c++. It adds some weird
Hello I have a problem wherein I have to read a huge csv file.
Hello everyone I have a problem. I want to do a GridView with a
Hello I have a very weird problem in chrome I just cannot figure out!
I have this problem when trying to run hello world program using android SDK.
Hello I am a Java web app developer I have a problem, I would

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.