Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8514797
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T04:58:06+00:00 2026-06-11T04:58:06+00:00

I have a table like the following one CREATE TABLE [dbo].[MyTable]( [MyTableID] [int] IDENTITY(1,1)

  • 0

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!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T04:58:08+00:00Added an answer on June 11, 2026 at 4:58 am

    Here is a start:

    -- rows for 1 but not in 2:
    
    SELECT FIELD_A, FIELD_B, FIELD_C, FIELD_D FROM dbo.MyTable WHERE ContainerID = 1
    EXCEPT
    SELECT FIELD_A, FIELD_B, FIELD_C, FIELD_D FROM dbo.MyTable WHERE ContainerID = 2;
    
    -- rows for 2 but not in 1:
    
    SELECT FIELD_A, FIELD_B, FIELD_C, FIELD_D FROM dbo.MyTable WHERE ContainerID = 2
    EXCEPT
    SELECT FIELD_A, FIELD_B, FIELD_C, FIELD_D FROM dbo.MyTable WHERE ContainerID = 1;
    
    -- rows in both:
    
    SELECT FIELD_A, FIELD_B, FIELD_C, FIELD_D FROM dbo.MyTable WHERE ContainerID = 1
    INTERSECT
    SELECT FIELD_A, FIELD_B, FIELD_C, FIELD_D FROM dbo.MyTable WHERE ContainerID = 2;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following table: CREATE TABLE [dbo].[Tree]( [AutoID] [int] IDENTITY(1,1) NOT NULL, [Category]
I have a table like this one CREATE TABLE MyTable ( [MyTableID] [int] NOT
I have the following table: CREATE TABLE [dbo].[EntityAttributeRelship]( [IdNmb] [int] IDENTITY(1,1) NOT NULL, [EntityIdNmb]
i have following 3 tables CREATE TABLE [dbo].[dspartner]( [dspartnerid] [bigint] IDENTITY(1,1) NOT NULL, [name]
suppose I have the following tables and relations: CREATE TABLE [dbo].[Customers] ( [CustomerID] [int]
I have a string like following: CREATE GLOBAL TEMPORARY TABLE some_temp_table_name or CREATE GLOBAL
Say you have a table layout like the following: couses : id (INT), courseName
I have a table like the following: RuleStep StepID | Step Property | Step
I have a table like the following: ID Output ------------------------- 01ABC1 AB 01ABC2 AB
Say I have a database table like the following: FileID | FileName | FileSize

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.