I want to get the value of "vid" knowing the node ID, and get the value of "name" for those rows where "vid" is equal to 2.
If it were a plain query, I would not know how to write it; I don't know how to write a left join query.
The "plain" SQL query in Drupal is the following:
$result = db_query('SELECT tid FROM {taxonomy_index} WHERE nid = :nid', array(':nid'=>$nid));
The equivalent raw SQL query is the following:
SELECT did, name FROM taxonomy_index as ti LEFT JOIN taxonomy_term_data AS ttd ON ti.tid = ttd.tid WHERE vid = 2 and nid = $nid