dbTalk Databases Forums  

slecting multiple distinct columns..

comp.databases.ms-sqlserver comp.databases.ms-sqlserver


Discuss slecting multiple distinct columns.. in the comp.databases.ms-sqlserver forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
vvyshak@gmail.com
 
Posts: n/a

Default slecting multiple distinct columns.. - 03-06-2006 , 10:58 PM






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...


Reply With Quote
  #2  
Old   
jennifer1970@hotmail.com
 
Posts: n/a

Default Re: slecting multiple distinct columns.. - 03-07-2006 , 01:42 PM






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.

vvyshak (AT) gmail (DOT) com wrote:
Quote:
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...


Reply With Quote
  #3  
Old   
Erland Sommarskog
 
Posts: n/a

Default Re: slecting multiple distinct columns.. - 03-07-2006 , 04:32 PM



(vvyshak (AT) gmail (DOT) com) writes:
Quote:
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, esquel (AT) sommarskog (DOT) 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


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.