468,103 Members | 1,243 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,103 developers. It's quick & easy.

slecting multiple distinct columns..

Hi all...
I have a table in which some columns has distinct values and some has
duplicates..i wan to select all the columns with distinct values....no
problem if rows has null value in it....i tried a lot wit distinct and
group by but nothing got worked out...
Waitin for your reply.....
Thanking you...

Mar 7 '06 #1
2 8390
Try the Having clause
For example, this will bring back records that have duplicate records
for Col1, Col2 and Col3.

If you want only records that have a single record, you can change ">
1" to "= 1".

SELECT DISTINCT
Col1, Col2, Col3, COUNT(*) as NumberDups
FROM SomeTable
GROUP BY Col1, Col2, Col3
HAVING COUNT(*) > 1
Of course, you could post your table definitions with Create statements
and insert statements so people could have data to work with to help
you.

vv*****@gmail.com wrote:
Hi all...
I have a table in which some columns has distinct values and some has
duplicates..i wan to select all the columns with distinct values....no
problem if rows has null value in it....i tried a lot wit distinct and
group by but nothing got worked out...
Waitin for your reply.....
Thanking you...


Mar 7 '06 #2
(vv*****@gmail.com) writes:
I have a table in which some columns has distinct values and some has
duplicates..i wan to select all the columns with distinct values....no
problem if rows has null value in it....i tried a lot wit distinct and
group by but nothing got worked out...
Waitin for your reply.....


I will have to admit that I have a poor understanding of what you are
asking for. But there is a standard recommendation for this sort of
questions, and that is that you post:

o CREATE TABLE statements for your table(s).
o INSERT statements with sample data.
o The desired output, given the sample data.
o A short description of the underlying business problem.
--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx
Mar 7 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

8 posts views Thread by Jason L James | last post: by
12 posts views Thread by Peter Proost | last post: by
6 posts views Thread by zaphod | last post: by
20 posts views Thread by p175 | last post: by
12 posts views Thread by Michel Esber | last post: by
1 post views Thread by Solo | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.