Skip to main content
Category:

Example How do I write a left join query in Drupal 8:

in this Example field_type is a List(text) field.

    $db = \Drupal::database();
    $query = $db->select('node_field_data', 'n');
    $query->condition('n.type', $node_type, '=')
        ->condition('n.status', '1', '=')
        ->fields('n', array('nid'))
        ->fields('n', array('title'));
    $query->leftJoin('node__field_type', 'n1', 'n1.entity_id = n.nid');
    $query->condition('n1.field_type_value', $type);
    $query->addTag('node_access');
    $query->range(0, 1);

Riadh Rahmi

Senior Web Developer PHP/Drupal & Laravel

I am a senior web developer, I have experience in planning and developing large scale dynamic web solutions especially in Drupal & Laravel.

Web Posts

Search

Page Facebook