tags:

views:

483

answers:

2
+3  A: 

How about:

SELECT COUNT(*)
FROM (SELECT DISTINCT a, b FROM MyTable)

For more information on why this can't be done in a simpler way (besides concatenating strings as noted in a different answer), you can refer to the this Google Answers post: Sql Distinct Count.

Roee Adler
+1  A: 

You could concatenate a and b together into 1 string like this (TSQL, hopefully something very similar in Sybase:

SELECT COUNT(DISTINCT(STR(a) + ',' + STR(b)))
FROM @YourTable
AdaTheDev
This wouldn't work if a or b are string columns containing commas
soulmerge
True, I was assuming they were integers. If they are strings, then any delimiter could be used...something like "{RANDOM_DELIM}". Just a case of deciding on a suitable delimiter I guess
AdaTheDev
The data that I'm interested in are stored as ints so this method works - I've just tested it!
Ian Hickman
While you're at it, test performance as well. I think this solution will be slower than what you originally tried it with.
Tomalak