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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T17:39:17+00:00 2026-05-30T17:39:17+00:00

This will be a bit abstract but I have a method like this: private

  • 0

This will be a bit abstract but I have a method like this:

private int[] ReturnLogicalGroupingAForOrderedElements(List<int> elements) {
    //sql query or linq query
    //returns an int[] in case there are more than one matching set.
}

Let’s say the List passed contains the following elements: 3,6 and 9. I need to find the exact same list, elements in the same order, sharing the same logical grouping (whatever it is), from a datatable source.

I have a datatable with the following columns (all of them int values):

LogicalGroupingA, LogicalGroupingB, Element, ElementOrder

I need to find and identify that all of the above elements (3,6,9) exists across several rows, sharing the same logical grouping. Example:

7,1,3,1
7,1,6,2
7,1,9,3

If all of these are found then I want to return the value from LogicalGroupingA which is 7.
But consider this, there might be a different set of rows (sharing same logicalgrouping) that are:

4,1,3,1
4,1,6,2
4,1,9,3
4,1,5,4

The query should only return the desired value if the complete series of elements is exactly what is asked for (here the first three elements are equal to the list queried for but since there’s a fourth element here it is not equal). Assume that the datatable rows are mixed. LogicalGroupingA can contain many of LogicalGroupingB which again can contain many Elements.

Originally I had a very simple datatable setup where a colum contained a string like “3,6,9” that I would have to parse in my logic. The aim by creating this new numeric datatable was to make it as fast as possible (in theory). I’m open for an alternative datatable structure if it can improve on this but mainly I’m asking for help forming the desired query (sql or linq) for the above table.

EDIT: Maybe a bit bad timing posting the question as I will be gone from my dev machine for the next two days but rest assure I will give the proper points & votes (and comments) once I am back and have tested the suggestions. Thanks for your patience.

  • 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-30T17:39:19+00:00Added an answer on May 30, 2026 at 5:39 pm
    public class Grouping
    {
       public int LGA{get;set;}
       public int LGB{get;set;}
       public int El {get;set;}
       public int ElO {get;set;}
    }
    
    void Main()
    {
        var dbValues = new List<Grouping>
            {
                new Grouping { LGA =7, LGB = 1, El=6, ElO=2 },
                new Grouping { LGA =7, LGB = 1, El=3, ElO=1 },
                new Grouping { LGA =4, LGB = 1, El=3, ElO=1 },
                new Grouping { LGA =4, LGB = 1, El=6, ElO=2 },
                new Grouping { LGA =4, LGB = 1, El=7, ElO=3 },
            };
        var dbGroups = dbValues.Select(dbData => new {Group = dbData.LGA, Element = dbData.El, ElO = dbData.ElO})
                .OrderBy(item => item.ElO)
                .GroupBy(item => item.Group);
        var elements = new List<int>{3, 6};
    
        foreach(var dbGroup in dbGroups)
        {
            if (dbGroup.Select(el => el.Element).SequenceEqual(elements))
            {
                Console.WriteLine(dbGroup.First().Group);
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The question plot (a bit abstract, but answering this question will help me in
This will be a bit subjective, I'm afraid, but I'd value the advice of
This is a bit hypothetical and grossly simplified but... Assume a program that will
This will be implemented in Javascript (jQuery) but I suppose the method could be
I have a method that has many many statements like this: employee.LastName = file.EMPLOYEE.NAME.SUBNAME.FAMILYNAME.NAMEPART1.Value;
Okay, this will be a bit hard to explain, but I'll try my best.
I am a bit lost as to how to explain this, so I will
This will hopefully be an easy one. I have an F# project (latest F#
This will probably be obvious but I can't find the best way. I want
This will be probable quite odd question. But i thought I will give it

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.