Skip to main content
Tweeted twitter.com/StackDrupal/status/783090883403124736
added 9 characters in body; edited tags; edited title
Source Link
avpaderno
  • 97.9k
  • 15
  • 164
  • 284

how to How do I write thea left join query in drupal 7.?

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 namevalue 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

how to write the left join query in drupal 7.

table: taxonomy_index and taxonomy_term_data. fields in taxonomy_index: nid, tid

fields in taxonomy_term_data. tid, vid, name

now, i want to according to the nid get the tid then get the name where vid=2.

if write a single query. i know how to do. but using join table, i don't know how to do.

single query:

$result = db_query('SELCET tid FROM {taxonomy_index} WHERE nid = :nid',array(':nid'=>$nid));

the sql query:

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

How do I write a left join query?

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
deleted 145 characters in body
Source Link
enjoylife
  • 3.8k
  • 7
  • 47
  • 73

table: taxonomy_index and taxonomy_term_data. fields in taxonomy_index: nid, tid

fields in taxonomy_term_data. tid, vid, name

now, i want to according to the nid get the tid then get the name where vid=2.

if write a single query. i know how to do. but using join table, i don't know how to do.

single query:

$result = db_query('SELCET tid FROM {taxonomy_index} WHERE nid = :nid',array(':nid'=>$nid));

i want to get all the vocabulary name(vid=2) of the node. i put this sql query in my phpmyadmin.but it doesn't work. what's wrong with it?:

select DISTINCT(nid)tid,name from taxonomy_index  as ti left join taxonomy_term_data as ttd left join on ti.tid= ttdtid=ttd.tid where vid=2 ,and nid=$nid

table: taxonomy_index and taxonomy_term_data. fields in taxonomy_index: nid, tid

fields in taxonomy_term_data. tid, vid, name

now, i want to according to the nid get the tid then get the name where vid=2.

if write a single query. i know how to do. but using join table, i don't know how to do.

single query:

$result = db_query('SELCET tid FROM {taxonomy_index} WHERE nid = :nid',array(':nid'=>$nid));

i want to get all the vocabulary name(vid=2) of the node. i put this sql query in my phpmyadmin.but it doesn't work. what's wrong with it?

select DISTINCT(nid),name from taxonomy_index  as ti left join taxonomy_term_data as ttd left join on ti.tid= ttd.tid where vid=2 ,nid=$nid

table: taxonomy_index and taxonomy_term_data. fields in taxonomy_index: nid, tid

fields in taxonomy_term_data. tid, vid, name

now, i want to according to the nid get the tid then get the name where vid=2.

if write a single query. i know how to do. but using join table, i don't know how to do.

single query:

$result = db_query('SELCET tid FROM {taxonomy_index} WHERE nid = :nid',array(':nid'=>$nid));

the sql query:

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
deleted 8 characters in body
Source Link
enjoylife
  • 3.8k
  • 7
  • 47
  • 73

table: taxonomy_index and taxonomy_term_data. fields in taxonomy_index: nid, tid

fields in taxonomy_term_data. tid, vid, name

now, i want to according to the nid get the tid then get the name where vid=2.

if write a single query. i know how to do. but using join table, i don't know how to do.

single query:

$result = db_query('SELCET tid FROM {taxonomy_index} WHERE nid = :nid',array(':nid'=>$nid));

i want to get all the vocabulary name(vid=2) of the node. i put this sql query in my phpmyadmin.but it doesn't work. what's wrong with it?

select DISTINCT(tid),DISTINCT(nid),name from taxonomy_index left as ti left join taxonomy_term_data as ttd left join on ti.tid= ttd.tid where vid=2 ,nid=$nid

table: taxonomy_index and taxonomy_term_data. fields in taxonomy_index: nid, tid

fields in taxonomy_term_data. tid, vid, name

now, i want to according to the nid get the tid then get the name where vid=2.

if write a single query. i know how to do. but using join table, i don't know how to do.

single query:

$result = db_query('SELCET tid FROM {taxonomy_index} WHERE nid = :nid',array(':nid'=>$nid));

i want to get all the vocabulary name(vid=2) of the node. i put this sql query in my phpmyadmin.but it doesn't work. what's wrong with it?

select DISTINCT(tid),DISTINCT(nid),name from taxonomy_index left as ti left join taxonomy_term_data as ttd left join on ti.tid= ttd.tid where vid=2

table: taxonomy_index and taxonomy_term_data. fields in taxonomy_index: nid, tid

fields in taxonomy_term_data. tid, vid, name

now, i want to according to the nid get the tid then get the name where vid=2.

if write a single query. i know how to do. but using join table, i don't know how to do.

single query:

$result = db_query('SELCET tid FROM {taxonomy_index} WHERE nid = :nid',array(':nid'=>$nid));

i want to get all the vocabulary name(vid=2) of the node. i put this sql query in my phpmyadmin.but it doesn't work. what's wrong with it?

select DISTINCT(nid),name from taxonomy_index  as ti left join taxonomy_term_data as ttd left join on ti.tid= ttd.tid where vid=2 ,nid=$nid
added 301 characters in body; added 4 characters in body
Source Link
enjoylife
  • 3.8k
  • 7
  • 47
  • 73
Loading
Source Link
enjoylife
  • 3.8k
  • 7
  • 47
  • 73
Loading