dadamssg Posted August 4, 2009 Share Posted August 4, 2009 Developing a forum. i have a table named Topics with the topic_name, content, create_date, created_by, and topic_id. And then i have a table name Responses with content, create_date, created_by, topic_id, and response_id. I want to list out the Topic names and then have the when the last response and who it it was by next to it, exactly like this forum. I am clueless how i would write the query to do that though. i need to combine this to pull up all topics $query = "SELECT * FROM Topics WHERE 1 ORDER BY create_date DESC"; with another query to pull up the last post date and user. anybody know how to do this? Quote Link to comment https://forums.phpfreaks.com/topic/168806-pull-up-last-post-with-topic-title-name/ Share on other sites More sharing options...
Bjom Posted August 4, 2009 Share Posted August 4, 2009 Just JOIN the tables (and don't use the asterisk - in joint tables it will lead to problems anyway) What is "WHERE 1" good for btw? SELECT Top.topic_name, Res.create_date, Res.created_by FROM Topics AS Top JOIN Responses as Res ON Top.topic_id = Res.topic_id ORDER BY create_date DESC LIMIT 1; Quote Link to comment https://forums.phpfreaks.com/topic/168806-pull-up-last-post-with-topic-title-name/#findComment-890603 Share on other sites More sharing options...
dadamssg Posted August 4, 2009 Author Share Posted August 4, 2009 alright, what if i want to pull the create_date from the topic as well? Quote Link to comment https://forums.phpfreaks.com/topic/168806-pull-up-last-post-with-topic-title-name/#findComment-890608 Share on other sites More sharing options...
dadamssg Posted August 4, 2009 Author Share Posted August 4, 2009 oh and does the limit 1 apply to the topics as well? i want to list ALL the topics i have in the table Quote Link to comment https://forums.phpfreaks.com/topic/168806-pull-up-last-post-with-topic-title-name/#findComment-890609 Share on other sites More sharing options...
Bjom Posted August 4, 2009 Share Posted August 4, 2009 did you try and simply run the query without the limit 1? did you try to simply write the extra field you want to query to the field list? Quote Link to comment https://forums.phpfreaks.com/topic/168806-pull-up-last-post-with-topic-title-name/#findComment-890809 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.