Sunday, March 11, 2012

curious result

How can I write a query to return non distinct results?Your question is a bit vague but maybe this example will help.
Duplicate last names in the Aithors table:

SELECT au_lname, COUNT(*)
FROM Pubs.dbo.Authors
GROUP BY au_lname
HAVING COUNT(*)>1

If you need more help please read the following article about the best
way to post your problem.

http://www.aspfaq.com/etiquette.asp?id=5006

--
David Portas
SQL Server MVP
--|||this works except I'm needing distinct combinations of several fields
such as

SELECT x, y, z, COUNT(*)
FROM table
GROUP BY x
HAVING COUNT(*)>1

David Portas wrote:

>Your question is a bit vague but maybe this example will help.
>Duplicate last names in the Aithors table:
>SELECT au_lname, COUNT(*)
> FROM Pubs.dbo.Authors
> GROUP BY au_lname
> HAVING COUNT(*)>1
>If you need more help please read the following article about the best
>way to post your problem.
>http://www.aspfaq.com/etiquette.asp?id=5006
>|||William Kossack (kossackw@.njc.org) writes:
> this works except I'm needing distinct combinations of several fields
> such as
> SELECT x, y, z, COUNT(*)
> FROM table
> GROUP BY x
> HAVING COUNT(*)>1

And that query is good for you? Or are you asking for more assistance?
In the latter case, please post:

o CREATE TABLE statment for the your table
o INSERT statement with sample data.
o The desired result given the sample.

if we have to guess what you are looking for, odds are that our
guesses will be wrong.

--
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techin.../2000/books.asp

No comments:

Post a Comment