SQL query order by creates duplicate content?

Here is my query:

$timesearch = TIME_NOW - 86400;
       $query = $db->query("
       SELECT p.dateline, p.tid, t.tid, t.uid, t.replies, t.views, t.fid, t.subject AS threadsubject, t.lastpost AS threadlastpost, t.lastposter, t.dateline AS threadage, t.lastposteruid, f.name AS name, u.username, u.usergroup, u.displaygroup, t.username AS author
       FROM ".TABLE_PREFIX."posts p
       LEFT JOIN " . TABLE_PREFIX . "threads t ON (t.tid = p.tid)
       LEFT JOIN ".TABLE_PREFIX."forums as f ON (f.fid = t.fid)
       LEFT JOIN " . TABLE_PREFIX . "users AS u ON (t.lastposteruid = u.uid)
       LEFT JOIN " . TABLE_PREFIX . "users AS l ON (t.uid = l.uid)
       WHERE {$fids} p.dateline >= $timesearch AND t.visible='1' AND t.closed NOT LIKE 'moved|%' AND p.visible='1' 
       order by p.dateline DESC
        LIMIT 100

I am not sure why it orders correctly but also leaves duplicates?

Since you don’t use DISTINCT and you don’t use GROUP BY , if the joined tables have a 1 to n relationship you’ll get “duplicate” data. The ordering has got nothing to do with that.

Ohhhh thanks fixed it by grouping by t.tid and ordering by t.lastpost