Database Management
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesDatabase Management

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:
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
  #1  
Old January 23rd, 2003, 10:22 PM
rob5408 rob5408 is offline
Certified Genius
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2001
Location: over there
Posts: 77 rob5408 User rank is Private First Class (20 - 50 Reputation Level)rob5408 User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 46 m 57 sec
Reputation Power: 7
Send a message via AIM to rob5408
select query with count

this may be simple but i haven't yet been able to figure it out...i have three tables invloved in this query...one for forums, one for the threads, and one for posts...the format is like this...

forums
forumID | forumTitle

threads
threadID | threadForum

posts
postID | postThread

all the IDs are auto increasing integers. threadForum is a foreign key that links a certain thread to which forum it is part of and postThread is a foreign key that links it to a thread...a thread has a series of posts related to it. with the lowest postID being the first post in the thread obviously. now how do i return a recordset with the rows being each forums title, a count of how many threads there in the forum, and a count of how many posts there are in a forum? the main problem i'm getting is that i can't get an aggregate function like count() to go with a row for each forum...does this involve two subqueries somehow?? anyone got any tutorials that will help? rob
__________________
Delenda est Carthago

Reply With Quote
  #2  
Old January 24th, 2003, 02:57 AM
pabloj's Avatar
pabloj pabloj is offline
Modding: Oracle MsSQL Firebird
Dev Shed God 6th Plane (7500 - 7999 posts)
 
Join Date: Jun 2001
Location: Outside US
Posts: 7,711 pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 2 Months 2 Weeks 6 Days 4 h 53 m 59 sec
Reputation Power: 259
What is the query you are trying to do?

SELECT forum.title, count(threads.threadID), count (posts.postID) FROM (posts INNER JOIN threads ON posts.postThread = threads.threadID) INNER JOIN forum ON threads.threadForum = forum.forumID GROUP BY posts.postID, threads.threadID

Could something like this help?

Reply With Quote
  #3  
Old January 24th, 2003, 02:56 PM
swampBoogie swampBoogie is offline
Contributing User
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Jan 2003
Location: Paris Uppland
Posts: 1,766 swampBoogie User rank is Sergeant Major (2000 - 5000 Reputation Level)swampBoogie User rank is Sergeant Major (2000 - 5000 Reputation Level)swampBoogie User rank is Sergeant Major (2000 - 5000 Reputation Level)swampBoogie User rank is Sergeant Major (2000 - 5000 Reputation Level)swampBoogie User rank is Sergeant Major (2000 - 5000 Reputation Level)swampBoogie User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 2 Weeks 4 Days 6 h 24 m 8 sec
Reputation Power: 37
Code:
select title,
  (select count(*) 
      from threads 
     where threadforum = f.forumid ) 
as threads,
  (select count(*) 
      from posts inner join threads
    on posts.posthread = threads.threadid
    where threads.threadforum = f.forumidid )
 as posts
  from forum f

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesDatabase Management > select query with count


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