Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Not sure if this is what you are getting at because your question is difficult to understand and it appears that your example data may contain a couple of typos. However, I modeled something similar for you below. Note I changed Row 1 because it looks like you had a typo, and I changed Row 5 so it would actually be an excluded case, otherwise you would have gotten everything.</p> <pre><code>public class Test { public int Row {get; set;} public int ID {get; set;} public string Match {get; set;} public string Value {get; set;} public int Equal {get; set;} public int Group {get; set;} } void Main() { var items = new List&lt;Test&gt;(); items.Add(new Test() {Row = 1, ID = 1, Match = "a", Value = "a", Equal = 1, Group = 1}); items.Add(new Test() {Row = 2, ID = 1, Match = "a", Value = "b", Equal = 0, Group = 1}); items.Add(new Test() {Row = 3, ID = 2, Match = "a", Value = "a", Equal = 1, Group = 2}); items.Add(new Test() {Row = 4, ID = 3, Match = "b", Value = "c", Equal = 0, Group = 3}); items.Add(new Test() {Row = 5, ID = 4, Match = "a", Value = "b", Equal = 1, Group = 4}); var result = items.GroupBy(i =&gt; i.Group) .Where(g =&gt; g.All(t =&gt; (t.Equal == 1 &amp;&amp; t.Match == t.Value) || (t.Equal == 0 &amp;&amp; t.Match != t.Value))) .SelectMany(g =&gt; g.Select(i =&gt; i)); foreach (var i in result) { Console.WriteLine("Row: {0}, ID: {1}", i.Row, i.ID); } } </code></pre> <p>Result:</p> <pre><code>Row: 1, ID: 1 Row: 2, ID: 1 Row: 3, ID: 2 Row: 4, ID: 3 </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload