Taking Sample in SQL Query <p>I'm working on a problem which is something like this :</p> <p>I have a table with many columns but major are <code>DepartmentId</code> and <code>EmployeeIds</code></p> <pre><code>Employee Ids Department Ids ------------------------------ A 1 B 1 C 1 D 1 AA 2 BB 2 CC 2 A1 3 B1 3 C1 3 D1 3 </code></pre> <p>I want to write a SQL query such that I take out 2 sample <code>EmployeeIds</code> for each <code>DepartmentID</code>.</p> <p>like</p> <pre><code>Employee Id Dept Ids B 1 C 1 AA 2 CC 2 D1 3 A1 3 </code></pre> <p>Currently I am writing the query,</p> <pre><code>select EmployeeId, DeptIds, count(*) from table_name group by 1,2 sample 2 </code></pre> <p>but it gives me total two rows.</p> <p>Any help?</p>