I have a table like the following one
CREATE TABLE [dbo].[MyTable](
[MyTableID] [int] IDENTITY(1,1) NOT NULL,
[ContainerID] [int] NOT NULL,
[FIELD_A] [nvarchar](15) NOT NULL,
[FIELD_B] [nvarchar](15) NOT NULL,
[FIELD_C] [nvarchar](15) NOT NULL,
[FIELD_D] [nvarchar](50) NULL,
CONSTRAINT [PK_MyTable] PRIMARY KEY CLUSTERED ( [MyTableID] ASC )
WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF,
ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 80) ON [PRIMARY]
) ON [PRIMARY]
In simple terms FIELD_A, FIELD_B, FIELD_C and FIELD_D are grouped by ContainerID.
Considering that each container contains about 2k records, I would like to execute a query that returns the differences between two ContainerID. For example, while comparing container 1 and container 2, I need to know:
- How many records are present in 1 and not in 2 and vice versa
- How many records are present in both containers
Which is the simplest way to get those results?
Thanks!
Here is a start: