0

I'm trying to do a equi join but it isn't working. I have 2 tables: Table 1 - taxonomy_term_data with fields "tid,vid,name,description,format,weight etc"

Table -2 -taxonomy_term_hierarchy with fields "tid and parent"

I have sql query with me it is working fine. This is the query "select t1. *,t2.vid,t2.name from taxonomy_term_hierarchy t1, taxonomy_term_data t2 where t1.tid = t2.tid AND vid=2 limit 5;"

I just want to get tid,name,vid from taxonomy_term_data table and parent from taxonomy_hierarchy table in db_select query format

2 Answers 2

0

You can built any type of select query using db_select, you can see in detail on following url https://api.drupal.org/api/drupal/includes!database!database.inc/function/db_select/7.x

0

You can change query based on you requirement.

$query = db_select('taxonomy_term_hierarchy', 't1');
    $query->join('taxonomy_term_data', 't2', 't1.tid = t2.tid');
    $result = $query
      ->fields('t1', array('tid', 'field1', 'field2'))
      ->fields('t2', array('tid', 'vid', 'name'))
      ->condition('t2.vid', '2')
      ->range(0,5);
      ->execute();

    foreach ($result as $row) {
      // Do something with $row.
    }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.