 <p>I think what you are looking for is something like:</p> <pre><code>foreach (var employee in details) { var groupCodes = from item in a where item.EmpID == employee.EmpID select item.GroupCode; // use groupCodes here... } </code></pre>