MS SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesMS SQL Development

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 Dev Shed Forums Sponsor:
  #1  
Old October 15th, 2004, 10:16 AM
mOrrI mOrrI is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Location: Portugal
Posts: 154 mOrrI User rank is Private First Class (20 - 50 Reputation Level)mOrrI User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 4 h 46 m 59 sec
Reputation Power: 5
Send a message via MSN to mOrrI
Question How can i select only entries with at least 2 rows?

heyas,
i wanna know how can i select only entries with at least 2 rows?
What i mean is that i want to make a select * from table1 where columnA = 'Something' order by columnB

but addicionally i want it to return only register that happen at least 2 times for columnB

thanks in advance!

Reply With Quote
  #2  
Old October 15th, 2004, 04:10 PM
r937's Avatar
r937 r937 is offline
SQL Consultant
Click here for more information.
 
Join Date: Feb 2003
Location: Toronto Canada
Posts: 17,654 r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level) 
Time spent in forums: 1 Month 3 Weeks 6 Days 12 h 49 m 28 sec
Reputation Power: 981
register?

could you please give some example rows and the result you expect?
__________________
r937.com | rudy.ca

Reply With Quote
  #3  
Old October 17th, 2004, 04:59 AM
iyad muhanna iyad muhanna is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2004
Posts: 7 iyad muhanna User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Try this, it should work

I think there is an easier way to do this, but this is what comes to my mind right now...

SELECT table1.*
FROM table1
INNER JOIN

(SELECT Column1, COUNT(Column1)
FROM table1
WHERE (Column1 = 'IYAD')
GROUP BY Column1
HAVING (COUNT(Column1) > 1))
AS tempTable

ON table.Column1 = tempTable.Column1
ORDER BY table.Column2

You are basically joining on the same table, thats why you are naming the second result set AS tempTable

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesMS SQL Development > How can i select only entries with at least 2 rows?


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 6 hosted by Hostway