Reputation: 231
I have two columns called topic_id and post_id, and what I want to do is find every row where the topic_id is the lowest for each post ID.
For example
topic_id post_id
1 5
2 5
3 8
4 8
So it would grab row 1 and 3.
I am not even sure where to begin so any help would be greatly appreciated.
Upvotes: 4
Views: 304
Reputation: 4315
I think you'd be able to do something like
SELECT MIN(`topic_id`), `post_id`
FROM `my_table`
GROUP BY `post_id`
Take a look GROUP BY
Upvotes: 0
Reputation: 135799
select post_id, min(topic_id)
from YourTable
group by post_id
Upvotes: 5