sql query help

nealr

Senior member
Dec 20, 2000
771
0
0
I have 2 tables,

TOPICS
topic_id
topic_description


POSTS
post_id
topic_id
post_description

what I want is a query to select all the items from TOPICS, but only one item from POSTS for each topic(the one with the lowest post_id).

Any idea how to do this query?
I can sorta do it, but I can't get my post_description field?

SELECT topics.topic_id, topics.topic_description, (select min (posts.post_id) from posts where topic_id=topics.topic_id)
FROM topics


thanks
 

nealr

Senior member
Dec 20, 2000
771
0
0
forget it, I figured it out

SELECT topics.topicid, topics.topictext,posts.post
FROM topics, posts
where posts.postid= (select min (posts.postid) from posts where topicid=topics.topicid)
 

jonmullen

Platinum Member
Jun 17, 2002
2,517
0
0
That kinda a clumsy query with the sub-query...I ham haveing a hard time understanding what you are wanting, but if you clarified I be I could help, but than again is speed is not of super importance that query should work fine in most SQL engins.