Note that there are some explanatory texts on larger screens.

plurals
  1. POReturn all groups that have exactly the same employees
    primarykey
    data
    text
    <p>There are 2 tables:</p> <pre><code>Employee (id_employee, worker_name) Groups (id_employee, group_name) </code></pre> <p>Here is creation script for you:</p> <pre><code>CREATE TABLE Employee ( id_employee int identity(1,1) NOT NULL CONSTRAINT PK_Employee PRIMARY KEY CLUSTERED, worker_name nvarchar(100) CONSTRAINT UQ_Employee_worker_name UNIQUE ); CREATE TABLE Groups ( id_employee int NOT NULL CONSTRAINT FK_Groups_id_employee FOREIGN KEY REFERENCES Employee (id_employee), group_name varchar(10) NOT NULL, CONSTRAINT PK_Groups PRIMARY KEY CLUSTERED (group_name, id_employee) ); INSERT Employee SELECT 'worker 1' UNION ALL SELECT 'worker 2' UNION ALL SELECT 'worker 3' UNION ALL SELECT 'worker 4'; INSERT Groups SELECT 1, 'a1' UNION ALL SELECT 2, 'a1' UNION ALL SELECT 3, 'a2' UNION ALL SELECT 4, 'a2' UNION ALL SELECT 1, 'b1' UNION ALL SELECT 2, 'b1' UNION ALL SELECT 3, 'b2' UNION ALL SELECT 4, 'b2' UNION ALL SELECT 2, 'b3' UNION ALL SELECT 3, 'b3' UNION ALL SELECT 4, 'b3'; </code></pre> <p>I need a query that for a given <code>id_group</code> will return all other groups that have exactly the same employees.</p> <p>For example:</p> <pre><code>SELECT for 'a1' </code></pre> <p>-> Should return 'b1' because in both groups there are: worker 1 &amp; worker 2</p> <pre><code>SELECT for 'a2' </code></pre> <p>-> Should return 'b2' because in both groups there are: worker 3 &amp; worker 4</p> <p>Note that groups need to be exactly the same, all members of <code>a1</code> need to be in <code>b1</code> and size of both groups need to be the same as well.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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