function SelectSubqueryTest::testNotExistsSubquerySelect
Same name in other branches
- 9 core/tests/Drupal/KernelTests/Core/Database/SelectSubqueryTest.php \Drupal\KernelTests\Core\Database\SelectSubqueryTest::testNotExistsSubquerySelect()
- 8.9.x core/tests/Drupal/KernelTests/Core/Database/SelectSubqueryTest.php \Drupal\KernelTests\Core\Database\SelectSubqueryTest::testNotExistsSubquerySelect()
- 10 core/tests/Drupal/KernelTests/Core/Database/SelectSubqueryTest.php \Drupal\KernelTests\Core\Database\SelectSubqueryTest::testNotExistsSubquerySelect()
Tests NOT EXISTS subquery conditionals on SELECT statements.
We essentially select all rows from the {test} table that don't have matching rows in the {test_people} table based on the shared name column.
File
-
core/
tests/ Drupal/ KernelTests/ Core/ Database/ SelectSubqueryTest.php, line 250
Class
- SelectSubqueryTest
- Tests the Select query builder.
Namespace
Drupal\KernelTests\Core\DatabaseCode
public function testNotExistsSubquerySelect() : void {
// Put George into {test_people}.
$this->connection
->insert('test_people')
->fields([
'name' => 'George',
'age' => 27,
'job' => 'Singer',
])
->execute();
// Base query to {test}.
$query = $this->connection
->select('test', 't')
->fields('t', [
'name',
]);
// Subquery to {test_people}.
$subquery = $this->connection
->select('test_people', 'tp')
->fields('tp', [
'name',
])
->where('[tp].[age] = [t].[age]');
$query->notExists($subquery);
// Ensure that we got the right number of records.
$people = $query->execute()
->fetchCol();
$this->assertCount(3, $people, 'NOT EXISTS query returned the correct results.');
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.