I would like to get some help on the DISTINCT 'option' in a SQL query.
What I need to do is this:
select from a phpbb table (phpbb_posts) the last 5 records, but I don't want to select a record if another record has the same topic_id
This would be a (simplified) example:
I do a select, ordered by the date
sql orders everything by date, takes the first record and nottices topic_id=3
then it selects the next topic and nottices topic_id=5
then it selects the next topic and nottices topic_id=4
then it selects the next topic and nottices topic_id=3 -> oops, I allready have a topic_id=3, so I leave out this row
then it selects the next topic and nottices topic_id=10
then it selects the next topic and nottices topic_id=3-> oops, I allready have a topic_id=3, so I leave out this row
then it selects the next topic and nottices topic_id=4
I hope it's clear what I want?
I checked mysql.org and this is the explanation I get:
The options DISTINCT, DISTINCTROW and ALL specify whether duplicate rows should be returned. The default is (ALL), all matching rows are returned. DISTINCT and DISTINCTROW are synonyms and specify that duplicate rows in the result set should be removed.
This is what I tried
$query = "SELECT post_id, DISTINCT topic_id, forum_id, poster_id, post_time WHERE forum_id='1' OR forum_id='3' OR forum_id='5' FROM phpbb_posts ORDER BY post_time DESC LIMIT 5";