SunQuest
           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:
Generate data entry and reporting .NET Web apps in minutes, straight from your database. Read our FREE whitepaper “Build Web 2.0 Applications Without Hand-Coding” Download now!
  #1  
Old June 27th, 2003, 07:45 PM
amber141 amber141 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Posts: 42 amber141 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 59 m 23 sec
Reputation Power: 6
Send a message via ICQ to amber141
Unhappy Query For Forum Threads

Hi,
I am currently working on a forum application with Access

I need to create an Sql query that will return the originial postings and all related replies. For example:
Original Posting
->Reply to Original Posting
->Reply to Reply to Original Posting
->Reply to Reply to Reply to Original Posting
->2nd Reply to Original Posting

Table(Message)
--------
Messge_ID
Message_Postby
Message_Title
Message_Body
Message_InReplyTo
Message_Parent
Message_Date
Message_Replies - No of replies to this topic

How would I query for all related messages in one query? I am using 2 queries now, one to get the Original Posting and another to get the replies.

For the number of replies, this field is updated everytime there is a reply to this thread. Is there a way to use aggregate function to count the number of replies for to each message?

Hope it's understandable.

Reply With Quote
  #2  
Old June 27th, 2003, 11:01 PM
victorpendleton victorpendleton is offline
Contributing User
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Jan 2003
Location: No es importante
Posts: 2,065 victorpendleton User rank is Private First Class (20 - 50 Reputation Level)victorpendleton User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 6 h 31 m 56 sec
Reputation Power: 8
With access you have sub-selects. If the table is somewhat `normalized` you may be able to retrieve a unique message id and select all postings related to that message ID.

Reply With Quote
  #3  
Old June 28th, 2003, 11:04 AM
ecit12's Avatar
ecit12 ecit12 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Posts: 411 ecit12 User rank is Corporal (100 - 500 Reputation Level)ecit12 User rank is Corporal (100 - 500 Reputation Level)ecit12 User rank is Corporal (100 - 500 Reputation Level)ecit12 User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 2 Days 12 h 42 m 14 sec
Reputation Power: 7
hmmm.. the ease of ur query is all dependent on how u set up ur relationship..

how does ur message ID field work..
does it go like this

2
2.1
2.2
2.2.1
2.2.2
2.2.3
2.3
2.4
??

Reply With Quote
  #4  
Old June 28th, 2003, 11:57 AM
amber141 amber141 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Posts: 42 amber141 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 59 m 23 sec
Reputation Power: 6
Send a message via ICQ to amber141
sub-select as in sub queries? How do I do that?

The Message_ID is just a Autonumber generated by the database in form of
1
2
2

Reply With Quote
  #5  
Old June 28th, 2003, 01:23 PM
victorpendleton victorpendleton is offline
Contributing User
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Jan 2003
Location: No es importante
Posts: 2,065 victorpendleton User rank is Private First Class (20 - 50 Reputation Level)victorpendleton User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 6 h 31 m 56 sec
Reputation Power: 8
select somecolum
from table1
where table1Key in (select keycolumn from table2)

Reply With Quote
  #6  
Old June 28th, 2003, 01:46 PM
amber141 amber141 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Posts: 42 amber141 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 59 m 23 sec
Reputation Power: 6
Send a message via ICQ to amber141
I think that will work if the replies are tied to one parent message. But in my case, replies got be tied to a reply to the parent message.

Reply With Quote
  #7  
Old June 28th, 2003, 02:02 PM
victorpendleton victorpendleton is offline
Contributing User
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Jan 2003
Location: No es importante
Posts: 2,065 victorpendleton User rank is Private First Class (20 - 50 Reputation Level)victorpendleton User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 6 h 31 m 56 sec
Reputation Power: 8
You should then be able to `daisy-chain` your way to the originating message. How are your message ids releated?

Reply With Quote
  #8  
Old June 28th, 2003, 02:09 PM
amber141 amber141 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Posts: 42 amber141 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 59 m 23 sec
Reputation Power: 6
Send a message via ICQ to amber141
Message_Parent is the Message_ID of each original post. If the Message is a original post, Message_Parent will be 0. Message_InReplyTo is the Message_ID of any post.

What do you mean by 'daisy-chain'? In the SQL or script?

Last edited by amber141 : June 28th, 2003 at 02:17 PM.

Reply With Quote
  #9  
Old June 28th, 2003, 02:21 PM
victorpendleton victorpendleton is offline
Contributing User
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Jan 2003
Location: No es importante
Posts: 2,065 victorpendleton User rank is Private First Class (20 - 50 Reputation Level)victorpendleton User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 6 h 31 m 56 sec
Reputation Power: 8
Does the original post have a message id? What is it? How is the reply message ID structured? And a reply to a reply?
Something like
Original: 1
Reply: 1.1
Reply to Reply: 1.1.1
Second reply: 1.2
Reply to second reply 1.2.1
and so on
would allow you retrieve all messages that derived from original post 1.

Reply With Quote
  #10  
Old June 28th, 2003, 02:40 PM
amber141 amber141 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Posts: 42 amber141 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 59 m 23 sec
Reputation Power: 6
Send a message via ICQ to amber141
No the Message_ID is not structured in that way. It is just a plain number.
But I got when you meant.
Is that the only way to query for this kind of forum threading?

Reply With Quote
  #11  
Old June 28th, 2003, 03:08 PM
victorpendleton victorpendleton is offline
Contributing User
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Jan 2003
Location: No es importante
Posts: 2,065 victorpendleton User rank is Private First Class (20 - 50 Reputation Level)victorpendleton User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 6 h 31 m 56 sec
Reputation Power: 8
Nothing is absolute. But being structred that way would increase your flexibility. Based on what you have displayed I do not see an easy correlation between an originating post and a fifth generation reply.

Reply With Quote
  #12  
Old June 28th, 2003, 09:41 PM
r937's Avatar
r937 r937 is offline
SQL Consultant
Dev Shed God 25th Plane (17000 - 17499 posts)
 
Join Date: Feb 2003
Location: Toronto Canada
Posts: 17,310 r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level) 
Time spent in forums: 1 Month 3 Weeks 5 Days 4 h 20 m 43 sec
Reputation Power: 888
message replies can be joined to the posts they are in reply to, by using a self-join

what you're asking for, amber, is recursion, and as far as i know, only oracle database directly supports that, using CONNECT BY syntax or something

if you're sure you never go deeper than 5 levels, you can use a six-table self join -- a bit awkward but it works

anyhow, linking a reply to its parent post using Message_Parent is an example of the adjacency model

do a google search for "celko nested set model" for another approach

here's a third way: http://www.sitepoint.com/article/1105

rudy

Reply With Quote
  #13  
Old June 28th, 2003, 10:09 PM
amber141 amber141 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Posts: 42 amber141 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 59 m 23 sec
Reputation Power: 6
Send a message via ICQ to amber141
I am using Access and dumping all the sql statements to the database. So it is not possible to have a 6 table self-join.
Thanks for the enlightment on the Hierarchical data.

Reply With Quote
  #14  
Old June 28th, 2003, 10:30 PM
r937's Avatar
r937 r937 is offline
SQL Consultant
Dev Shed God 25th Plane (17000 - 17499 posts)
 
Join Date: Feb 2003
Location: Toronto Canada
Posts: 17,310 r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level) 
Time spent in forums: 1 Month 3 Weeks 5 Days 4 h 20 m 43 sec
Reputation Power: 888
i do six-table joins in access all the time

i know it's possible

Reply With Quote
  #15  
Old June 28th, 2003, 10:38 PM
amber141 amber141 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Posts: 42 amber141 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 59 m 23 sec
Reputation Power: 6
Send a message via ICQ to amber141
How did you do that?!
I can't make sense of a self-join. Now that's another thing to read up on.

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesDatabase Management > Query For Forum Threads


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread: