Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 I want to get the difference of data rows between

Author  Topic 

cplusplus
Aged Yak Warrior

567 Posts

Posted - 2013-03-21 : 16:36:44
I want to get the difference of data rows between two tables.

I have table1 and table 2, both has column ACCT_UNIT.

In table1, i have 170 rows and in table 2 i have 350 rows.

I want to see teh difference of data between both tables.

select acct_unit from table1; has 170 rows
select acct_unit from table2; has 350 rows


Thank you very much for the helpful info.

Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2013-03-21 : 17:53:39
http://msdn.microsoft.com/en-us/library/ms188055.aspx
Go to Top of Page

bandi
Master Smack Fu Yak Hacker

2242 Posts

Posted - 2013-03-22 : 00:29:52

select acct_unit from table2
EXCEPT
select acct_unit from table1;


select acct_unit from table1
EXCEPT
select acct_unit from table2;

--
Chandu
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-03-22 : 00:33:47
[code]
select acct_unit from table2 t2
WHERE NOT EXISTS (SELECT 1 FROM table1 WHERE acct_unit = t2.acct_unit )

select acct_unit from table1 t1
WHERE NOT EXISTS (SELECT 1 FROM table2 WHERE acct_unit = t1.acct_unit )
[/code]

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

cplusplus
Aged Yak Warrior

567 Posts

Posted - 2013-03-22 : 08:03:06
Thank you all for the helpful info.
Go to Top of Page

bandi
Master Smack Fu Yak Hacker

2242 Posts

Posted - 2013-03-22 : 09:38:33
quote:
Originally posted by cplusplus

Thank you all for the helpful info.


Welcome

--
Chandu
Go to Top of Page
   

- Advertisement -