locked
How to compared data between two table with same database RRS feed

  • Question

  • User511367801 posted

    Hi.

    Im using VS2008 and SQL Server Management Studio 2008.

    I want to ask, i have two different table, TableA and TableB in same database, DatabaseX.

    Both table have two same column, ColumnY but the data are different within this table.

    Example: 

    TableA, ColumnY : A1, B2, C3, D4

    TableB, ColumnY : A1, B2, C3, D4, E5, F6, G7

    I want to compared data between this two table in my program. How the SQL Statement look alike?

    Monday, May 18, 2015 11:44 PM

Answers

  • User197322208 posted

    difference

    https://msdn.microsoft.com/en-us/library/ms188753.aspx

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, May 19, 2015 12:57 AM
  • User61956409 posted

    Hi appleblue,

    Thanks for your post.

    Please try the following SQL Statement.

    SELECT ColumnY FROM TableA
    
    SELECT ColumnY FROM TableB
    
    SELECT [ColumnY ]
    FROM TableB 
    WHERE [ColumnY ] NOT IN (SELECT [ColumnY ]
    FROM TableA)
    

    Best Regards,

    Fei Han

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, May 20, 2015 1:26 AM

All replies

  • User197322208 posted

    difference

    https://msdn.microsoft.com/en-us/library/ms188753.aspx

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, May 19, 2015 12:57 AM
  • User61956409 posted

    Hi appleblue,

    Thanks for your post.

    Please try the following SQL Statement.

    SELECT ColumnY FROM TableA
    
    SELECT ColumnY FROM TableB
    
    SELECT [ColumnY ]
    FROM TableB 
    WHERE [ColumnY ] NOT IN (SELECT [ColumnY ]
    FROM TableA)
    

    Best Regards,

    Fei Han

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, May 20, 2015 1:26 AM