function DatabaseSelectTestCase::testUnion in SimpleTest 7
Test that we can UNION multiple Select queries together. This is semantically equal to UNION DISTINCT, so we don't explicity test that.
File
- tests/
database_test.test, line 1364
Class
- DatabaseSelectTestCase
- Test the SELECT builder.
Code
function testUnion() {
$query_1 = db_select('test', 't')
->fields('t', array(
'name',
))
->condition('age', array(
27,
28,
), 'IN');
$query_2 = db_select('test', 't')
->fields('t', array(
'name',
))
->condition('age', 28);
$query_1
->union($query_2);
$names = $query_1
->execute()
->fetchCol();
// Ensure we only get 2 records.
$this
->assertEqual(count($names), 2, t('UNION correctly discarded duplicates.'));
$this
->assertEqual($names[0], 'George', t('First query returned correct name.'));
$this
->assertEqual($names[1], 'Ringo', t('Second query returned correct name.'));
}