Database object syntax for where conditions giving error I am trying to convert the following SQL query in calls to the database API.

SELECT p.id, p.message,t.posted, p.posted AS reply_date,p.poster_id,t.id,t.subject, t.forum_id FROM punbb.punbb_posts AS p JOIN punbb.punbb_topics AS t ON p.topic_id = t.id WHERE p.id = t.first_post_id;


What I get is the following code. 

$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;condition('t.first_post_id','p.id');


The code generates the following SQL query.

    SELECT p.id AS id, p.message AS message, p.posted AS posted, p.poster_id AS poster_id, t.posted AS t_posted, t.id AS t_id, t.subject AS subject, t.forum_id AS forum_id, t.first_post_id AS first_post_id
FROM 
{punbb_posts} p
INNER JOIN {punbb_topics} t ON p.topic_id = t.id
WHERE  (t.first_post_id = :db_condition_placeholder_0)


Why can't I get "PID"?
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');