Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 The opposite of DISTINCT?

Author  Topic 

nomadsoul
Yak Posting Veteran

89 Posts

Posted - 2006-10-30 : 19:59:36
Hello,
I've done numerous select statements using DISTINCT, but what if I want to do the opposite of DISTINCT meaning I wantduplicate values but don't want single values?
I have not coded much in T-SQL mainly MySQL. I certaily like TSQL, and Im using the new Sql Server Express 2005, love it.

It is better to be prepared and not have an opportunity than to not be prepared and have an opportunity

MichaelP
Jedi Yak

2489 Posts

Posted - 2006-10-30 : 20:03:52
Something like this should do it


SELECT Field1, Field2, Field3, COUNT(*)
FROM MyTable
GROUP BY Field1, Field2, Field3
HAVING COUNT(*) > 1


Michael

<Yoda>Use the Search page you must. Find the answer you will. Cursors, path to the Dark Side they are. Avoid them, you must. Use Order By NewID() to get a random record you will.</Yoda>

Opinions expressed in this post are not necessarily those of TeleVox Software, inc. All information is provided "AS IS" with no warranties and confers no rights.
Go to Top of Page

nomadsoul
Yak Posting Veteran

89 Posts

Posted - 2006-10-30 : 20:10:25
Thanks MP
That was awesome fast. That was my first post here and naturally I didn't see the search link.
I am trying it now

It is better to be prepared and not have an opportunity than to not be prepared and have an opportunity
Go to Top of Page

MichaelP
Jedi Yak

2489 Posts

Posted - 2006-10-30 : 21:24:07
No worries about the Search. These days, it's not very effective. You'll find with posts here, most are answered rather quickly, esp during working hours in the USA.

Michael

<Yoda>Use the Search page you must. Find the answer you will. Cursors, path to the Dark Side they are. Avoid them, you must. Use Order By NewID() to get a random record you will.</Yoda>

Opinions expressed in this post are not necessarily those of TeleVox Software, inc. All information is provided "AS IS" with no warranties and confers no rights.
Go to Top of Page
   

- Advertisement -