Microsoft SQL Server
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsDatabaseMicrosoft SQL Server

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old December 15th, 2004, 12:09 PM
flamesburn flamesburn is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Posts: 26 flamesburn User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 20 m 35 sec
Reputation Power: 0
returning only unique records

Hello, Im looking to return only records that are unique and if a record is not unique not return it.

i.e.
if i had 30, 30, 45 I know distinct would return 30, 45

Im looking for something that would only return 45

any ideas?

thanks in advance for the help

JH

Reply With Quote
  #2  
Old December 15th, 2004, 12:59 PM
A2k's Avatar
A2k A2k is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Posts: 166 A2k User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 18 h 44 m 10 sec
Reputation Power: 4
Count the number of values you have, this will give you 1 record for each value

select count(value), value
from table

you'll end up with something like this

count of value ¦ value
2¦30
1¦45

in your where statement exclude count(value)>1


select count(value), value
from table
where count(value)=1

Reply With Quote
  #3  
Old December 15th, 2004, 04:38 PM
A2k's Avatar
A2k A2k is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Posts: 166 A2k User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 18 h 44 m 10 sec
Reputation Power: 4
I have posted this on another thread aswell, it just occured to me it would be helpful here too:

Try a select distinct, this will give you all unique rows.

Reply With Quote
  #4  
Old December 30th, 2004, 08:38 AM
Dumbo Dumbo is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Posts: 29 Dumbo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 27 m 31 sec
Reputation Power: 0
Thumbs up How about this:

select col1
from table
group by col1
having count(col1)=1

Reply With Quote
  #5  
Old December 30th, 2004, 09:01 AM
Memnoch's Avatar
Memnoch Memnoch is offline
Unholy Moderator
ASP Free God 14th Plane (11500 - 11999 posts)
 
Join Date: Oct 2003
Location: In hell, where did you think?
Posts: 11,760 Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level) 
Time spent in forums: 3 Weeks 5 Days 5 h 22 m 16 sec
Reputation Power: 443
You need to GROUP BY the field HAVING COUNT(fieldname) = 1.

Exactly like Dumbo's example.

Reply With Quote
Reply

Viewing: ASP Free ForumsDatabaseMicrosoft SQL Server > returning only unique records


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway