SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsDatabaseSQL 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 ASP Free Forums Sponsor:
  #1  
Old September 7th, 2004, 11:52 PM
lesue11 lesue11 is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Aug 2004
Posts: 4 lesue11 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Question Many-to-Many query with multiple conditions

Ok here is the table structure I have:

picture
picID
filename
etc.

picsubject
picID
subjectID

subject
subjectID
subjectname
etc.

Say one picID (01) has more than one subject listed in the picsubject table. I would place the data in more than one row as such:
picID subjectID
01 10
01 11

How would you perform a query that finds the picID that contains a subjectID of both 10 and 11? Anybody have any suggestions?
Thanks

Reply With Quote
  #2  
Old September 8th, 2004, 11:35 AM
sbaxter sbaxter is offline
Moderator: Access, SQL
ASP Free God (5000 - 5499 posts)
 
Join Date: Oct 2003
Posts: 5,126 sbaxter User rank is Corporal (100 - 500 Reputation Level)sbaxter User rank is Corporal (100 - 500 Reputation Level)sbaxter User rank is Corporal (100 - 500 Reputation Level)sbaxter User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 4 Days 1 h 2 m 51 sec
Reputation Power: 13
SELECT [picsubject].[picID], Count([picsubject].[subjectID]) AS CountOfsubjectID
FROM picsubject
WHERE ((([picsubject].[subjectID])="10" Or ([picsubject].[subjectID])="11"))
GROUP BY [picsubject].[picID]
HAVING (((Count(picsubject.subjectID))=2));

s-

Reply With Quote
  #3  
Old September 10th, 2004, 12:00 AM
lesue11 lesue11 is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Aug 2004
Posts: 4 lesue11 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Thanks man it worked.

Reply With Quote
Reply

Viewing: ASP Free ForumsDatabaseSQL Development > Many-to-Many query with multiple conditions


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 3 hosted by Hostway
Stay green...Green IT