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 5849113
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T12:57:14+00:00 2026-05-22T12:57:14+00:00

I previously asked the question and got answer to Best approach to write query

  • 0

I previously asked the question and got answer to Best approach to write query but the problem is that if you have to save this result in a list then there duplication of records. For example
the resultant table of the join given EXAMPLE

See there are duplicate rows. How can you filter them out, and yet save the data of order number?
Of course there may be some ways but I am looking for some great ways

How can we store the data in list and not create duplicate rows in list?

My current code for my tables is

  int lastUserId = 0;
  sql_cmd = new SqlCommand();
  sql_cmd.Connection = sql_con;

  sql_cmd.CommandText = "SELECT * FROM AccountsUsers LEFT JOIN Accounts ON AccountsUsers.Id = Accounts.userId ORDER BY AccountsUsers.accFirstName";
  SqlDataReader reader = sql_cmd.ExecuteReader();

  if (reader.HasRows == true)
  {
      Users userToAdd = new Users();

      while (reader.Read())
      {
           userToAdd = new Users();
           userToAdd.userId = int.Parse(reader["Id"].ToString());
           userToAdd.firstName = reader["accFirstName"].ToString();
           userToAdd.lastName = reader["accLastName"].ToString();
           lastUserId = userToAdd.userId;

           Websites domainData = new Websites();
           domainData.domainName = reader["accDomainName"].ToString();
           domainData.userName = reader["accUserName"].ToString();
           domainData.password = reader["accPass"].ToString();
           domainData.URL = reader["accDomain"].ToString();
           userToAdd.DomainData.Add(domainData);

           allUsers.Add(userToAdd);
       }
    }

For second table I have custom list that will hold the entries of all the data in second table.

The table returned is table having joins and have multiple rows for same

  • 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-22T12:57:15+00:00Added an answer on May 22, 2026 at 12:57 pm

    Besides using the Dictionary idea as answered by Antonio Bakula…

    If you persist the dictionary of users and call the code in your sample multiple times you should consider that a user account is either new, modifed, or deleted.

    The algorithm to use is the following when executing your SQL query:

    1. If row in query result is not in dictionary create and add new user to the dictionary.
    2. If row in query result is in dictionary update the user information.
    3. If dictionary item not in query result delete the user from the dictionary.

    I’d also recommend not using SELECT *
    Use only the table columns your code needs, this improves the performance of your code, and prevents a potential security breach by returning private user information.

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

Sidebar

Related Questions

I asked a similar question about this previously, but I did not specify that
I have seen this question asked previously but can not find a clear explanation
This is in reference to the question previously asked The problem here is, each
I previously asked a question that I still have not been able to solve:
I previously asked a similar question on this topic a while back and got
I have previously asked two questions Question 1 and Question 2 but there is
This question builds off of a previously asked question: Pass by reference multidimensional array
Previously, I asked the question . The problem is the demands of our file
Ok, i've read most relevant questions asked here previously on this but I still
OK, I know that this has been asked previously, so please forgive me for

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.