function SelectSubqueryTest::testExistsSubquerySelect
Same name in other branches
- 9 core/tests/Drupal/KernelTests/Core/Database/SelectSubqueryTest.php \Drupal\KernelTests\Core\Database\SelectSubqueryTest::testExistsSubquerySelect()
- 10 core/tests/Drupal/KernelTests/Core/Database/SelectSubqueryTest.php \Drupal\KernelTests\Core\Database\SelectSubqueryTest::testExistsSubquerySelect()
- 11.x core/tests/Drupal/KernelTests/Core/Database/SelectSubqueryTest.php \Drupal\KernelTests\Core\Database\SelectSubqueryTest::testExistsSubquerySelect()
Tests EXISTS subquery conditionals on SELECT statements.
We essentially select all rows from the {test} table that have matching rows in the {test_people} table based on the shared name column.
File
-
core/
tests/ Drupal/ KernelTests/ Core/ Database/ SelectSubqueryTest.php, line 210
Class
- SelectSubqueryTest
- Tests the Select query builder.
Namespace
Drupal\KernelTests\Core\DatabaseCode
public function testExistsSubquerySelect() {
// 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.name = t.name');
$query->exists($subquery);
$result = $query->execute();
// Ensure that we got the right record.
$record = $result->fetch();
$this->assertEquals('George', $record->name, 'Fetched name is correct using EXISTS query.');
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.