Database object syntax for where conditions giving error
You need a where():

$query = db_select('punbb_posts', 'p')
-&gt;fields('p', array('id', 'message', 'posted', 'poster_id'));
$query-&gt;join('punbb_topics', 't', 'p.topic_id = t.id');
$query-&gt;addField('t', 'posted');
$query-&gt;addField('t', 'id');
$query-&gt;addField('t', 'subject');
$query-&gt;addField('t', 'forum_id');
$query-&gt;addField('t', 'first_post_id');
$query-&gt;where('t.first_post_id = p.id');