table: taxonomy_index
and taxonomy_term_data
.
fields in taxonomy_index
: nid,
tid
fields in taxonomy_term_data
. tid
, vid
, name
now, iI want to according to the nid
get the tid
thenvalue of "vid" knowing the node ID, and get the name
value of "name" for those rows where vid=2
"vid" is equal to 2.
if writeIf it were a singleplain query. i, I would not know how to do. but using join table, iwrite it; I don't know how to dowrite a left join query.
singleThe "plain" SQL query in Drupal is the following:
$result = db_query('SELCET'SELECT tid FROM {taxonomy_index} WHERE nid = :nid', array(':nid'=>$nid));
the sqlThe equivalent raw SQL query is the following:
select tid,name from taxonomy_index as ti left join taxonomy_term_data as ttd on ti.tid=ttd.tid where vid=2 and nid=$nid
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