Drupal 10: Creating A Union Database Query

$query1 = \Drupal::database()->select('node', 'n');
$query1->condition('n.type', 'page');
$query1->addField('n', 'nid');

$query2 = \Drupal::database()->select('node', 'n');
$query2->condition('n.type', 'article');
$query2->addField('n', 'nid');

$query = \Drupal::database()->select($query1->union($query2), 'n');

$results = $query->execute();


Add new comment

The content of this field is kept private and will not be shown publicly.
12 + 8 =
Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.