Given the following table setup
Table
column1
column2
forumCategory
ID
name
forum
ID
name
forumCategoryID
ForumTopics
ID
forumID
ForumTopicMsg
ID
topicID
dateEntered
I am attempting to create a query that gives a complete overview which will
show all the forumCategory's, followed by all its forums while giving a
count of all topics belonging to that forum, counting all msgs belonging to
that topic, and the date of the last msg belonging to that topic.
forumCategory.name
forum.name, Count(forumTopics.ID), Count(forumTopicMsg.ID),
Newest(forumTopicMsg.dateEntered)
forum.name, Count(forumTopics.ID), Count(forumTopicMsg.ID),
Newest(forumTopicMsg.dateEntered)
forum.name, Count(forumTopics.ID), Count(forumTopicMsg.ID),
Newest(forumTopicMsg.dateEntered)
forum.name, Count(forumTopics.ID), Count(forumTopicMsg.ID),
Newest(forumTopicMsg.dateEntered)
forumCategory.name
forum.name, Count(forumTopics.ID), Count(forumTopicMsg.ID),
Newest(forumTopicMsg.dateEntered)
forum.name, Count(forumTopics.ID), Count(forumTopicMsg.ID),
Newest(forumTopicMsg.dateEntered)
forum.name, Count(forumTopics.ID), Count(forumTopicMsg.ID),
Newest(forumTopicMsg.dateEntered)
forum.name, Count(forumTopics.ID), Count(forumTopicMsg.ID),
Newest(forumTopicMsg.dateEntered)
forumCategory.name
forum.name, Count(forumTopics.ID), Count(forumTopicMsg.ID),
Newest(forumTopicMsg.dateEntered)
forum.name, Count(forumTopics.ID), Count(forumTopicMsg.ID),
Newest(forumTopicMsg.dateEntered)
forum.name, Count(forumTopics.ID), Count(forumTopicMsg.ID),
Newest(forumTopicMsg.dateEntered)
forum.name, Count(forumTopics.ID), Count(forumTopicMsg.ID),
Newest(forumTopicMsg.dateEntered)
I cannot figure out how to maintain a relationship across all table and
still returning all info. This is further compounded by the fact that I
need to also return the forum.name even if no topic(s) yet exist for that
forum. So my attempts at using a group by clause have failed. I would
appreciate any help or insight anyone could offer. 4 1231
I think this will do it:
select
ForumCategory = fc.name,
ForumName = f.name,
NumberOfTopics = count(ft.id),
NumberOfMsgs = count(ftm.id),
LastUpdate = (Select max(dateentered) from ForumTopicMsg where topicid =
ft.id)
from forumCategory as fc
inner join forum as f
on (fc.id=f.forumCategoryID)
inner join forumTopics a ft
on (f.ID=ft.forumID)
inner join forumTopicMsg as ftm
on (ft.id=ftm.topicid)
group by fc.name, f.name
But a couple other things. You should really keep your foreign key
information consistent, there should be only one "id" that points to a
primary key of another table. For example:
forumCategory
fc_id
fc_name
forum
forum_id
fc_id
forum_name
You can use whatever naming standards you want (like I used both a fc_ and a
<tablename>_ type prefix) - that doesn't matter, so long as it's clear - but
the much bigger issue is that if you call forumCategory.fc_id - it needs to
be called fc_id everywhere else too.
HTH
"Bryan Martin" <sp**@myplaceinspace.com> wrote in message
news:9y********************@twister.southeast.rr.c om... Given the following table setup
Table column1 column2
forumCategory ID name
forum ID name forumCategoryID
ForumTopics ID forumID
ForumTopicMsg ID topicID dateEntered
I am attempting to create a query that gives a complete overview which will show all the forumCategory's, followed by all its forums while giving a count of all topics belonging to that forum, counting all msgs belonging to that topic, and the date of the last msg belonging to that topic.
forumCategory.name forum.name, Count(forumTopics.ID), Count(forumTopicMsg.ID), Newest(forumTopicMsg.dateEntered) forum.name, Count(forumTopics.ID), Count(forumTopicMsg.ID), Newest(forumTopicMsg.dateEntered) forum.name, Count(forumTopics.ID), Count(forumTopicMsg.ID), Newest(forumTopicMsg.dateEntered) forum.name, Count(forumTopics.ID), Count(forumTopicMsg.ID), Newest(forumTopicMsg.dateEntered) forumCategory.name forum.name, Count(forumTopics.ID), Count(forumTopicMsg.ID), Newest(forumTopicMsg.dateEntered) forum.name, Count(forumTopics.ID), Count(forumTopicMsg.ID), Newest(forumTopicMsg.dateEntered) forum.name, Count(forumTopics.ID), Count(forumTopicMsg.ID), Newest(forumTopicMsg.dateEntered) forum.name, Count(forumTopics.ID), Count(forumTopicMsg.ID), Newest(forumTopicMsg.dateEntered) forumCategory.name forum.name, Count(forumTopics.ID), Count(forumTopicMsg.ID), Newest(forumTopicMsg.dateEntered) forum.name, Count(forumTopics.ID), Count(forumTopicMsg.ID), Newest(forumTopicMsg.dateEntered) forum.name, Count(forumTopics.ID), Count(forumTopicMsg.ID), Newest(forumTopicMsg.dateEntered) forum.name, Count(forumTopics.ID), Count(forumTopicMsg.ID), Newest(forumTopicMsg.dateEntered)
I cannot figure out how to maintain a relationship across all table and still returning all info. This is further compounded by the fact that I need to also return the forum.name even if no topic(s) yet exist for that forum. So my attempts at using a group by clause have failed. I would appreciate any help or insight anyone could offer.
To add to RCS's post
Look at using an OUTER JOIN for those tables where rows may not exit.
Such as
select
ForumCategory = fc.name,
ForumName = f.name,
NumberOfTopics = count(ft.id),
NumberOfMsgs = count(ftm.id),
LastUpdate = (Select max(dateentered) from ForumTopicMsg where topicid
= ft.id)
from forumCategory as fc
inner join forum as f on (fc.id=f.forumCategoryID)
LEFT JOIN forumTopics a ft on (f.ID=ft.forumID)
LEFT JOIN forumTopicMsg as ftm on (ft.id=ftm.topicid)
group by fc.name, f.name
More information on the types of joins is available in Books online.
John
RCS wrote: I think this will do it:
select ForumCategory = fc.name, ForumName = f.name, NumberOfTopics = count(ft.id), NumberOfMsgs = count(ftm.id), LastUpdate = (Select max(dateentered) from ForumTopicMsg where
topicid = ft.id) from forumCategory as fc inner join forum as f on (fc.id=f.forumCategoryID) inner join forumTopics a ft on (f.ID=ft.forumID) inner join forumTopicMsg as ftm on (ft.id=ftm.topicid) group by fc.name, f.name
But a couple other things. You should really keep your foreign key information consistent, there should be only one "id" that points to
a primary key of another table. For example:
forumCategory fc_id fc_name
forum forum_id fc_id forum_name
You can use whatever naming standards you want (like I used both a
fc_ and a <tablename>_ type prefix) - that doesn't matter, so long as it's
clear - but the much bigger issue is that if you call forumCategory.fc_id - it
needs to be called fc_id everywhere else too.
HTH
"Bryan Martin" <sp**@myplaceinspace.com> wrote in message news:9y********************@twister.southeast.rr.c om... Given the following table setup
Table column1 column2
forumCategory ID name
forum ID name forumCategoryID
ForumTopics ID forumID
ForumTopicMsg ID topicID dateEntered
I am attempting to create a query that gives a complete overview
which will show all the forumCategory's, followed by all its forums while
giving a count of all topics belonging to that forum, counting all msgs
belonging to that topic, and the date of the last msg belonging to that
topic. forumCategory.name forum.name, Count(forumTopics.ID), Count(forumTopicMsg.ID), Newest(forumTopicMsg.dateEntered) forum.name, Count(forumTopics.ID), Count(forumTopicMsg.ID), Newest(forumTopicMsg.dateEntered) forum.name, Count(forumTopics.ID), Count(forumTopicMsg.ID), Newest(forumTopicMsg.dateEntered) forum.name, Count(forumTopics.ID), Count(forumTopicMsg.ID), Newest(forumTopicMsg.dateEntered) forumCategory.name forum.name, Count(forumTopics.ID), Count(forumTopicMsg.ID), Newest(forumTopicMsg.dateEntered) forum.name, Count(forumTopics.ID), Count(forumTopicMsg.ID), Newest(forumTopicMsg.dateEntered) forum.name, Count(forumTopics.ID), Count(forumTopicMsg.ID), Newest(forumTopicMsg.dateEntered) forum.name, Count(forumTopics.ID), Count(forumTopicMsg.ID), Newest(forumTopicMsg.dateEntered) forumCategory.name forum.name, Count(forumTopics.ID), Count(forumTopicMsg.ID), Newest(forumTopicMsg.dateEntered) forum.name, Count(forumTopics.ID), Count(forumTopicMsg.ID), Newest(forumTopicMsg.dateEntered) forum.name, Count(forumTopics.ID), Count(forumTopicMsg.ID), Newest(forumTopicMsg.dateEntered) forum.name, Count(forumTopics.ID), Count(forumTopicMsg.ID), Newest(forumTopicMsg.dateEntered)
I cannot figure out how to maintain a relationship across all table
and still returning all info. This is further compounded by the fact
that I need to also return the forum.name even if no topic(s) yet exist
for that forum. So my attempts at using a group by clause have failed. I
would appreciate any help or insight anyone could offer.
Thx RCS and John
"John Bell" <jb************@hotmail.com> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com... To add to RCS's post
Look at using an OUTER JOIN for those tables where rows may not exit. Such as
select ForumCategory = fc.name, ForumName = f.name, NumberOfTopics = count(ft.id), NumberOfMsgs = count(ftm.id), LastUpdate = (Select max(dateentered) from ForumTopicMsg where topicid = ft.id) from forumCategory as fc inner join forum as f on (fc.id=f.forumCategoryID) LEFT JOIN forumTopics a ft on (f.ID=ft.forumID) LEFT JOIN forumTopicMsg as ftm on (ft.id=ftm.topicid) group by fc.name, f.name
More information on the types of joins is available in Books online.
John
RCS wrote: I think this will do it:
select ForumCategory = fc.name, ForumName = f.name, NumberOfTopics = count(ft.id), NumberOfMsgs = count(ftm.id), LastUpdate = (Select max(dateentered) from ForumTopicMsg where topicid = ft.id) from forumCategory as fc inner join forum as f on (fc.id=f.forumCategoryID) inner join forumTopics a ft on (f.ID=ft.forumID) inner join forumTopicMsg as ftm on (ft.id=ftm.topicid) group by fc.name, f.name
But a couple other things. You should really keep your foreign key information consistent, there should be only one "id" that points to a primary key of another table. For example:
forumCategory fc_id fc_name
forum forum_id fc_id forum_name
You can use whatever naming standards you want (like I used both a fc_ and a <tablename>_ type prefix) - that doesn't matter, so long as it's clear - but the much bigger issue is that if you call forumCategory.fc_id - it needs to be called fc_id everywhere else too.
HTH
"Bryan Martin" <sp**@myplaceinspace.com> wrote in message news:9y********************@twister.southeast.rr.c om... > Given the following table setup > > Table > column1 > column2 > > forumCategory > ID > name > > forum > ID > name > forumCategoryID > > ForumTopics > ID > forumID > > ForumTopicMsg > ID > topicID > dateEntered > > I am attempting to create a query that gives a complete overview which > will show all the forumCategory's, followed by all its forums while giving > a count of all topics belonging to that forum, counting all msgs belonging > to that topic, and the date of the last msg belonging to that topic. > > forumCategory.name > forum.name, Count(forumTopics.ID), Count(forumTopicMsg.ID), > Newest(forumTopicMsg.dateEntered) > forum.name, Count(forumTopics.ID), Count(forumTopicMsg.ID), > Newest(forumTopicMsg.dateEntered) > forum.name, Count(forumTopics.ID), Count(forumTopicMsg.ID), > Newest(forumTopicMsg.dateEntered) > forum.name, Count(forumTopics.ID), Count(forumTopicMsg.ID), > Newest(forumTopicMsg.dateEntered) > forumCategory.name > forum.name, Count(forumTopics.ID), Count(forumTopicMsg.ID), > Newest(forumTopicMsg.dateEntered) > forum.name, Count(forumTopics.ID), Count(forumTopicMsg.ID), > Newest(forumTopicMsg.dateEntered) > forum.name, Count(forumTopics.ID), Count(forumTopicMsg.ID), > Newest(forumTopicMsg.dateEntered) > forum.name, Count(forumTopics.ID), Count(forumTopicMsg.ID), > Newest(forumTopicMsg.dateEntered) > forumCategory.name > forum.name, Count(forumTopics.ID), Count(forumTopicMsg.ID), > Newest(forumTopicMsg.dateEntered) > forum.name, Count(forumTopics.ID), Count(forumTopicMsg.ID), > Newest(forumTopicMsg.dateEntered) > forum.name, Count(forumTopics.ID), Count(forumTopicMsg.ID), > Newest(forumTopicMsg.dateEntered) > forum.name, Count(forumTopics.ID), Count(forumTopicMsg.ID), > Newest(forumTopicMsg.dateEntered) > > I cannot figure out how to maintain a relationship across all table and > still returning all info. This is further compounded by the fact that I > need to also return the forum.name even if no topic(s) yet exist for that > forum. So my attempts at using a group by clause have failed. I would > appreciate any help or insight anyone could offer. > >
Woops - yep, that's right.. with my way, it would only bring back rows if
there were messages in each topic..
Using a left outer join, will bring back the forum level data, and just have
0's for the number of topics, number of msgs and lastupdate should be
blank..
"Bryan Martin" <sp**@myplaceinspace.com> wrote in message
news:JB********************@twister.southeast.rr.c om... Thx RCS and John
"John Bell" <jb************@hotmail.com> wrote in message news:11**********************@o13g2000cwo.googlegr oups.com... To add to RCS's post
Look at using an OUTER JOIN for those tables where rows may not exit. Such as
select ForumCategory = fc.name, ForumName = f.name, NumberOfTopics = count(ft.id), NumberOfMsgs = count(ftm.id), LastUpdate = (Select max(dateentered) from ForumTopicMsg where topicid = ft.id) from forumCategory as fc inner join forum as f on (fc.id=f.forumCategoryID) LEFT JOIN forumTopics a ft on (f.ID=ft.forumID) LEFT JOIN forumTopicMsg as ftm on (ft.id=ftm.topicid) group by fc.name, f.name
More information on the types of joins is available in Books online.
John
RCS wrote: I think this will do it:
select ForumCategory = fc.name, ForumName = f.name, NumberOfTopics = count(ft.id), NumberOfMsgs = count(ftm.id), LastUpdate = (Select max(dateentered) from ForumTopicMsg where topicid = ft.id) from forumCategory as fc inner join forum as f on (fc.id=f.forumCategoryID) inner join forumTopics a ft on (f.ID=ft.forumID) inner join forumTopicMsg as ftm on (ft.id=ftm.topicid) group by fc.name, f.name
But a couple other things. You should really keep your foreign key information consistent, there should be only one "id" that points to a primary key of another table. For example:
forumCategory fc_id fc_name
forum forum_id fc_id forum_name
You can use whatever naming standards you want (like I used both a fc_ and a <tablename>_ type prefix) - that doesn't matter, so long as it's clear - but the much bigger issue is that if you call forumCategory.fc_id - it needs to be called fc_id everywhere else too.
HTH
"Bryan Martin" <sp**@myplaceinspace.com> wrote in message news:9y********************@twister.southeast.rr.c om... > Given the following table setup > > Table > column1 > column2 > > forumCategory > ID > name > > forum > ID > name > forumCategoryID > > ForumTopics > ID > forumID > > ForumTopicMsg > ID > topicID > dateEntered > > I am attempting to create a query that gives a complete overview which > will show all the forumCategory's, followed by all its forums while giving > a count of all topics belonging to that forum, counting all msgs belonging > to that topic, and the date of the last msg belonging to that topic. > > forumCategory.name > forum.name, Count(forumTopics.ID), Count(forumTopicMsg.ID), > Newest(forumTopicMsg.dateEntered) > forum.name, Count(forumTopics.ID), Count(forumTopicMsg.ID), > Newest(forumTopicMsg.dateEntered) > forum.name, Count(forumTopics.ID), Count(forumTopicMsg.ID), > Newest(forumTopicMsg.dateEntered) > forum.name, Count(forumTopics.ID), Count(forumTopicMsg.ID), > Newest(forumTopicMsg.dateEntered) > forumCategory.name > forum.name, Count(forumTopics.ID), Count(forumTopicMsg.ID), > Newest(forumTopicMsg.dateEntered) > forum.name, Count(forumTopics.ID), Count(forumTopicMsg.ID), > Newest(forumTopicMsg.dateEntered) > forum.name, Count(forumTopics.ID), Count(forumTopicMsg.ID), > Newest(forumTopicMsg.dateEntered) > forum.name, Count(forumTopics.ID), Count(forumTopicMsg.ID), > Newest(forumTopicMsg.dateEntered) > forumCategory.name > forum.name, Count(forumTopics.ID), Count(forumTopicMsg.ID), > Newest(forumTopicMsg.dateEntered) > forum.name, Count(forumTopics.ID), Count(forumTopicMsg.ID), > Newest(forumTopicMsg.dateEntered) > forum.name, Count(forumTopics.ID), Count(forumTopicMsg.ID), > Newest(forumTopicMsg.dateEntered) > forum.name, Count(forumTopics.ID), Count(forumTopicMsg.ID), > Newest(forumTopicMsg.dateEntered) > > I cannot figure out how to maintain a relationship across all table and > still returning all info. This is further compounded by the fact that I > need to also return the forum.name even if no topic(s) yet exist for that > forum. So my attempts at using a group by clause have failed. I would > appreciate any help or insight anyone could offer. > >
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Dave |
last post by:
After following Microsofts admonition to reformat my system before doing a
final compilation of my app I got many warnings/errors upon compiling an rtf
file created in word. I used the Help...
|
by: wukexin |
last post by:
Help me, good men. I find mang books that introduce bit "mang header
files",they talk too bit,in fact it is my too fool, I don't learn it, I have
do a test program, but I have no correct doing...
|
by: Colin J. Williams |
last post by:
Python advertises some basic service:
C:\Python24>python
Python 2.4.1 (#65, Mar 30 2005, 09:13:57) on
win32
Type "help", "copyright", "credits" or "license" for more information.
>>>
With...
|
by: Corepaul |
last post by:
Missing Help Files
When I enter "recordset" as the keyword and search the Visual Basic Help index,
I get many topics of interest in the resulting list. But there isn't any
information available...
|
by: Steve |
last post by:
I have written a help file (chm) for a DLL and referenced it using Help.ShowHelp
My expectation is that a developer using my DLL would be able to access this help file during his development time...
|
by: Mark |
last post by:
I have loaded Visual Studio .net on my home computer and my laptop, but my
home computer has an abbreviated help screen not 2% of the help on my laptop.
All the settings look the same on both...
|
by: JonathanOrlev |
last post by:
Hello everybody,
I wrote this comment in another message of mine, but decided to post it
again as a standalone message.
I think that Microsoft's Office 2003 help system is horrible, probably...
|
by: trunxnirvana007 |
last post by:
'UPGRADE_WARNING: Array has a new behavior. Click for more: 'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="9B7D5ADD-D8FE-4819-A36C-6DEDAF088CC7"'
'UPGRADE_WARNING: Couldn't resolve...
|
by: hitencontractor |
last post by:
I am working on .NET Version 2003 making an SDI application that calls MS Excel 2003.
I added a menu item called "MyApp Help" in the end of the menu bar to show Help-> About.
The application...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
| |