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
 General SQL Server Forums
 New to SQL Server Programming
 Find a duplicate

Author  Topic 

rsullivan
Starting Member

2 Posts

Posted - 2014-11-11 : 14:02:41
I have 3 fields Company, vendor, invoice and I am having trouble with this query. I need to determine when Vendor and Invoice are the same and occur greater than once while company is different.

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2014-11-11 : 14:37:51
select vendor, invoice, count(*)
from yourtable
group by vendor, invoice
having count(*) > 1

Tara Kizer
SQL Server MVP since 2007
http://weblogs.sqlteam.com/tarad/
Go to Top of Page

rsullivan
Starting Member

2 Posts

Posted - 2014-11-11 : 14:56:37
Sorry I really didn't word that correctly.. What I was trying to do is Vendor and invoice are the same but the company is not the same.
cmp vend inv
cmp1 vndr1 inv1
cmp1 vndr1 inv1
cmp2 vndr1 inv1



Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2014-11-11 : 14:58:55
select vend, inv, cmp, count(*)
from yourtable
group by vend, inv, cmp
having count(*) > 1

Tara Kizer
SQL Server MVP since 2007
http://weblogs.sqlteam.com/tarad/
Go to Top of Page
   

- Advertisement -