SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 I want to get the difference of data rows between
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

cplusplus
Aged Yak Warrior

540 Posts

Posted - 03/21/2013 :  16:36:44  Show Profile  Reply with Quote
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
Flowing Fount of Yak Knowledge

4614 Posts

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

bandi
Flowing Fount of Yak Knowledge

India
2217 Posts

Posted - 03/22/2013 :  00:29:52  Show Profile  Reply with Quote

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

India
52317 Posts

Posted - 03/22/2013 :  00:33:47  Show Profile  Reply with Quote

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 )


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

Go to Top of Page

cplusplus
Aged Yak Warrior

540 Posts

Posted - 03/22/2013 :  08:03:06  Show Profile  Reply with Quote
Thank you all for the helpful info.
Go to Top of Page

bandi
Flowing Fount of Yak Knowledge

India
2217 Posts

Posted - 03/22/2013 :  09:38:33  Show Profile  Reply with Quote
quote:
Originally posted by cplusplus

Thank you all for the helpful info.


Welcome

--
Chandu
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.08 seconds. Powered By: Snitz Forums 2000