Jump to content

[SOLVED] no freaking clue


dadamssg

Recommended Posts

Ok....deep breath....I have two tables. One for forum topics with the structure

 

title  varchar(100)

created_by  varchar(20)

create_date  datetime

topic_id  int(11)

content  text

views  int(11)

replies  int(11)

last_user  varchar(20)

last_time  datetime

 

and one that holds the responses to those topics

 

created_by  varchar(20)

create_date  datetime

topic_id  int(11)

response_id  int(11)

content  text

 

what i want to do is create a query that pulls up the topics that you've responded to BUT someone else posted a response since yours. Exactly like "Show new replies to your posts." link on this forum. any clues?

Link to comment
Share on other sites

Hi

 

Not sure how much of the topics you want, but this should get you the topic ids:-

 

SELECT DISTINCT a.topic_id
FROM responses a
INNER JOIN (
SELECT topic_id, MAX(create_date) AS maxCreateDate
FROM responses
WHERE created_by = '$MyName'
GROUP BY topic_id ) b
ON a.topic_id = b.topic_id
AND a.create_date > b.maxCreateDate

 

Might well be a more efficient way to do it  but I cannot see it at the moment.

 

All the best

 

Keith

Link to comment
Share on other sites

wow...that was impressive. It's almost what i want. This pulls up all the responses after a certain user's response. What i want is it to select the Topics. So....this pulls up the correct topic_id numbers...but i want it to pull these out of the Topic table so i can have all the info in the Topic rows. Does that make sence?

Link to comment
Share on other sites

SOLVED...thanks again kickstart!

 

SELECT * FROM Topics WHERE topic_id IN (SELECT DISTINCT a.topic_id
FROM Responses a
INNER JOIN (
SELECT topic_id, MAX(create_date) AS maxCreateDate
FROM Responses
WHERE created_by = '$userr'
GROUP BY topic_id ) b
ON a.topic_id = b.topic_id
AND a.create_date > b.maxCreateDate)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.