tags:

views:

89

answers:

2

Assuming the following structure, I need to find if there are cases where there's more than one DESC for each CP4+CP3 combination. I need only to know if they exist. Not where they are.

CP4, integer
CP3, integer
DESC, varchar(50)

+4  A: 

You can check using a self join: if the following query returns any rows, there's more than one DESC for a CP4+CP3 combination:

select     * 
from       YourTable a
inner join YourTable b
on         a.CP3 = b.CP3
           and a.CP4 = b.CP4
           and a.DESC <> b.DESC

A group by would work too:

select   count(*)
from     YourTable
group by CP3, CP4
having   count(distinct DESC) > 1

By the way, DESC is a SQL keyword; you might have to escape it in a way specific to your database.

Andomar
Perfect. Thank you Andomar :)
Krugar
A: 
StuffHappens