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 8788139
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T22:05:35+00:00 2026-06-13T22:05:35+00:00

I have two tables in a SQL Server 2008 database in which I want

  • 0

I have two tables in a SQL Server 2008 database in which I want to find:

  • values present in both tables (with all columns present in both tables)
  • values present in first table but not in second table
  • values present in second table but not in first table

Code:

CREATE TABLE #_temp
(ATM INT, Fault INT)

CREATE TABLE #_temp1
(ATM INT, Fault INT)

INSERT INTO #_temp  VALUES (10,101), (11,101), (12,101), (12,101), (10,105), (13,101)
INSERT INTO #_temp1 VALUES (10,102), (11,101), (12,103), (12,100), (10,105), (13,101)

/* My Try

SELECT * FROM #_temp t RIGHT JOIN #_temp1 t1 ON t.ATM=t1.ATM AND t.Fault=t.Fault AND t.ATM IS NULL AND t.Fault IS NULL

SELECT * FROM #_temp t JOIN #_temp1 t1 ON t.ATM=t1.ATM AND t.Fault=t.Fault

*/

DROP Table #_temp
DROP Table #_temp1 
  • 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-13T22:05:36+00:00Added an answer on June 13, 2026 at 10:05 pm

    To find values that exist in one table and not another you should use a where clause to determine the nulls:

    Create Table #_temp
    (ATM Int,Fault Int)
    
    Create Table #_temp1
    (ATM Int,Fault Int)
    
    Insert Into #_temp Values(10,101),(11,101),(12,101),(12,101),(10,105),(13,101)
    Insert Into #_temp1 Values(10,102),(11,101),(12,103),(12,100),(10,105),(13,101)
    
    
    --Values Present in both Table
    
    SELECT t.* 
    FROM #temp t
        INNER JOIN #_temp1 t1
            ON t.[ATM Int] = t1.[ATM Int]
            AND t.[Fault Int] = t1.[Fault Int]
    
    --Values Present in First Table But not in Second
    
    SELECT t.* 
    FROM #temp t
        LEFT JOIN #_temp1 t1
            ON t.[ATM Int] = t1.[ATM Int]
            AND t.[Fault Int] = t1.[Fault Int]
    WHERE t1.[ATM Int] IS NULL
    
    --Values Present in Second Table But not in First
    
    SELECT t.* 
    FROM #_temp1 t
        LEFT JOIN #temp t1
            ON t.[ATM Int] = t1.[ATM Int]
            AND t.[Fault Int] = t1.[Fault Int]
    WHERE t1.[ATM Int] IS NULL
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have SQL Server 2008 Ent and OLTP database with two big tables. How
I'm using SQL Server 2008 R2 and I have a database which contains two
I am creating a new SQL Server 2008 database. I have two two tables
I have a SQL Server 2008 database. This database has two related tables: Customer
In SQL Server 2008: I have two tables, dtlScheme and dtlRenewal, with a one
In SQL Server 2008 I have two tables. One table for users: id_user -
I'm using SQL Server 2008. Let's say I have two hypothetical tables like below:
This is SQL Server 2008. I have these two tables and a join: DECLARE
We have two tables in a SQL Server 2005 database, A and B.There is
Good Afternoon All, I have two tables in my SQL Server 2005 DB, Main

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.