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

  • SEARCH
  • Home
  • 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 225225
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T19:23:33+00:00 2026-05-11T19:23:33+00:00

I have two lists of two different kinds of objects representing data rows from

  • 0

I have two lists of two different kinds of objects representing data rows from two sql queries. The first list contains data, and the second contains more detailed data. So as an example:

List1:        List2:
 1   Alice     1   15
 2   Bob       1   19
 3   Carol     2    5
 4   Dave      2    7
               2   20
               4   16

I want to insert rows into List2 so that everyone in List1 has at least one row in List2. So when no rows exist in List2 for a certain person, I want to insert a single one with a default value. In the example case I would have to insert one row for Carol, so I would end up with:

List1:        List2:
 1   Alice     1   15
 2   Bob       1   19
 3   Carol     2    5
 4   Dave      2    7
               2   20
               3    0
               4   16

Does anyone have a clever, clean and efficient way of doing this?

I know that to join these tables together into one I would have to use an Outer Join, for example like in this Outer Join Sample. But I don’t want a new result set. I just want those missing rows to be inserted into List2.

Note: Yes, I know the question\title is kind of… blah… but I don’t know how to formulate it better. Someone please fix it if you can.

Note 2: I can not use SQL. I can not insert those rows in the original table. I am reporting on data, which means I do not touch any of the data. I just read it out. The data is to be used in a master-detail report, and my issue is that when no details exist for a certain master row, then you end up with just an empty space. Which is not good. So I want to insert rows with sensible info so that the user can see that there was nothing to show here.

  • 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-05-11T19:23:33+00:00Added an answer on May 11, 2026 at 7:23 pm

    Assuming your lists are sorted by the Key value like in your example (in this case an integer), something like this should work:

    int i = 0;
    
    foreach (var item in List1)
    {
        // Skip any items in List2 that don't exist in List1
        // (not sure this is needed in your case), or that we've
        // already passed in List1
        while (List2[i].Key < item.Key)
            i++;
    
        if (List2[i].Key > item.Key)
        {
            // Create new item in List2
            List2.Add(new List2Item(item.Key, 0));
        }
    }
    
    // TODO: resort List2
    

    Depending on how many items you expect to be missing, you might want to Insert into List2 instead, eliminating the need for the resorting. If you expect a lot of items to be missing however, this method will be faster. Alternatively, you could use a linked list for List2.

    Note that this will fail if there are duplicate Key entries in List1. You’d need to check for that seperately to prevent multiple new items from being created in List2.

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

Sidebar

Ask A Question

Stats

  • Questions 130k
  • Answers 130k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer From perlfunc(1): system LIST [...] The return value is the… May 12, 2026 at 6:09 am
  • Editorial Team
    Editorial Team added an answer The docs for the Python data model advise using __new__:… May 12, 2026 at 6:09 am
  • Editorial Team
    Editorial Team added an answer Are you horribly opposed to using a ManyToMany relationship? This… May 12, 2026 at 6:09 am

Related Questions

In my specific case, I have two kinds of messages that I need to
I have the situation where i use GIS software which stores the information about
I have a non document-based Core Data application. There's an NSTreeController that manages a
I ran into a scenario where LINQ to SQL acts very strangely. I would

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.