Unix Technical Forum

slecting multiple distinct columns..

This is a discussion on slecting multiple distinct columns.. within the SQL Server forums, part of the Microsoft SQL Server category; --> Hi all... I have a table in which some columns has distinct values and some has duplicates..i wan to ...


Go Back   Unix Technical Forum > Database Server Software > Microsoft SQL Server > SQL Server

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-29-2008, 07:36 PM
vvyshak@gmail.com
 
Posts: n/a
Default 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...

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 02-29-2008, 07:37 PM
jennifer1970@hotmail.com
 
Posts: n/a
Default Re: slecting multiple distinct columns..

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


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 02-29-2008, 07:37 PM
Erland Sommarskog
 
Posts: n/a
Default Re: slecting multiple distinct columns..

(vvyshak@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, esquel@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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
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
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 02:35 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com