jambla Posted October 2, 2007 Share Posted October 2, 2007 Hello, I want to select distinct values from ‘posts’. In the ‘posts’ table there are: pst_id - this is the post id for each posted item. mem_id - this is the member id. top_id - this is the topic id that the post (pst_id) is under. posted – this is the time the post (pst_id) was posted. I have no problem with this part: $query = "SELECT DISTINCT pst_id, mem_id, posted FROM posts ORDER BY posts.posted DESC LIMIT 0, 10"; It outputs: Latest Forum Posts Author - Title - Time 100002 100003 8:14 am 100003 100002 5:12 am 100003 100001 5:04 am 100000 100000 8:59 pm Now heres the part I cant seem to do. I want the Author values (10002 etc…) to look in the ‘members’ table and output the persons name. The members table looks like this: mem_id: 100002 username: Joe mem_id: 100003 username: Jill etc… and I want the Title value (10003 etc…) to look in the ‘topics’ table and output the topic subject title. The topics table looks like this: top_id: 100003 mem_id: 100002 subject: Do you like the color blue? top_id: 100002 mem_id: 100003 subject: Do you like the color red? etc… I am able to output this from the database without using using DISTINCT. But I only want one subject to show. I am using MySQL Version: 4.1.10 If I forgot any info please let me know as this is my first posting. Thanks for your help! Quote Link to comment Share on other sites More sharing options...
fenway Posted October 2, 2007 Share Posted October 2, 2007 You just need to JOIN in those other tables... but it sounds like you want GROUP BY, not DISTINCT. Quote Link to comment 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.