QueryBuilder
API reference › yii › db › mssql › QueryBuilder
QueryBuilder is the query builder for MS SQL Server databases (version 2019 and above).
Properties
Section titled “Properties”| Property | Type | Description | Defined by |
|---|---|---|---|
$db | yii\ | The database connection. Default: null. | yii\ |
$separator | string | The separator between different fragments of a SQL statement. Default: ' '. | yii\ |
$typeMap | array | Mapping from abstract column types (keys) to physical column types (values). Default: [\. | QueryBuilder |
$conditionClasses protected | array | Map of condition aliases to condition classes. Default: []. Available since 2.0.14. | yii\ |
$expressionBuilders protected | string[]|yii\[] | Maps expression class to expression builder class. Default: []. Available since 2.0.14. | yii\ |
Methods
Section titled “Methods”| Method | Description | Defined by |
|---|---|---|
__construct() | Constructor. | yii\ |
__call() | Calls the named method which is not a class method. | yii\ |
__get() | Returns the value of an object property. | yii\ |
__isset() | Checks if a property is set, i.e. defined and not null. | yii\ |
__set() | Sets value of an object property. | yii\ |
__unset() | Sets an object property to null. | yii\ |
addCheck() | Creates a SQL command for adding a check constraint to an existing table. | yii\ |
addColumn() | Builds a SQL statement for adding a new DB column. | yii\ |
addCommentOnColumn() | Builds a SQL command for adding comment to column. | QueryBuilder |
addCommentOnTable() | Builds a SQL command for adding comment to table. | QueryBuilder |
addDefaultValue() | Creates a SQL command for adding a default value constraint to an existing table. | QueryBuilder |
addForeignKey() | Builds a SQL statement for adding a foreign key constraint to an existing table. | yii\ |
addPrimaryKey() | Builds a SQL statement for adding a primary key constraint to an existing table. | yii\ |
addUnique() | Creates a SQL command for adding an unique constraint to an existing table. | yii\ |
alterColumn() | Builds a SQL statement for changing the definition of a column. | QueryBuilder |
batchInsert() | Generates a batch INSERT SQL statement. | yii\ |
bindParam() | Helper method to add $value to $params array using PARAM_PREFIX. | yii\ |
build() | Generates a SELECT SQL statement from a Query object. | yii\ |
buildColumns() | Processes columns and properly quotes them if necessary. | yii\ |
buildCondition() | Parses the condition specification and generates the corresponding SQL expression. | yii\ |
buildExpression() | Builds given $expression | yii\ |
buildFrom() | yii\ | |
buildGroupBy() | yii\ | |
buildHaving() | yii\ | |
buildJoin() | yii\ | |
buildLimit() | yii\ | |
buildOrderBy() | yii\ | |
buildOrderByAndLimit() | Builds the ORDER BY and LIMIT/OFFSET clauses and appends them to the given SQL. | QueryBuilder |
buildSelect() | yii\ | |
buildUnion() | yii\ | |
buildUnionOrderByAndLimit() | Builds the global ORDER BY and LIMIT/OFFSET clauses for a UNION query. | QueryBuilder |
buildWhere() | yii\ | |
buildWithQueries() | QueryBuilder | |
canGetProperty() | Returns a value indicating whether a property can be read. | yii\ |
canSetProperty() | Returns a value indicating whether a property can be set. | yii\ |
checkIntegrity() | Builds a SQL statement for enabling or disabling integrity checks on table constraints. | QueryBuilder |
className() static | Returns the fully qualified name of this class. | yii\ |
createConditionFromArray() | Transforms $condition defined in array format (as described in Query::where() to instance of ConditionInterface according to $conditionClasses map. | yii\ |
createIndex() | Builds a SQL statement for creating a new index. | yii\ |
createTable() | Builds a SQL statement for creating a new DB table. | yii\ |
createView() | Creates a SQL View. | yii\ |
delete() | Creates a DELETE SQL statement. | QueryBuilder |
dropCheck() | Creates a SQL command for dropping a check constraint. | yii\ |
dropColumn() | Drop all constraints before column delete. | QueryBuilder |
dropCommentFromColumn() | Builds a SQL command for adding comment to column. | QueryBuilder |
dropCommentFromTable() | Builds a SQL command for adding comment to table. | QueryBuilder |
dropDefaultValue() | Creates a SQL command for dropping a default value constraint. | QueryBuilder |
dropForeignKey() | Builds a SQL statement for dropping a foreign key constraint. | yii\ |
dropIndex() | Builds a SQL statement for dropping an index. | yii\ |
dropPrimaryKey() | Builds a SQL statement for removing a primary key constraint to an existing table. | yii\ |
dropTable() | Builds a SQL statement for dropping a DB table. | yii\ |
dropUnique() | Creates a SQL command for dropping an unique constraint. | yii\ |
dropView() | Drops a SQL View. | yii\ |
executeResetSequence() | Execute a SQL statement for resetting the sequence value of a table’s primary key. | yii\ |
getColumnType() | Converts an abstract column type into a physical column type. | QueryBuilder |
getExpressionBuilder() | Gets object of ExpressionBuilderInterface that is suitable for $expression. | yii\ |
hasMethod() | Returns a value indicating whether a method is defined. | yii\ |
hasProperty() | Returns a value indicating whether a property is defined. | yii\ |
init() | Initializes the object. | yii\ |
insert() | Creates an INSERT SQL statement. | QueryBuilder |
renameColumn() | Builds a SQL statement for renaming a column. | QueryBuilder |
renameTable() | Builds a SQL statement for renaming a DB table. | QueryBuilder |
resetSequence() | Creates a SQL statement for resetting the sequence value of a table’s primary key. | QueryBuilder |
selectExists() | Creates a SELECT EXISTS() SQL statement. | QueryBuilder |
setConditionClasses() | Setter for $conditionClasses property. | yii\ |
setExpressionBuilders() | Setter for $expressionBuilders property. | yii\ |
truncateTable() | Builds a SQL statement for truncating a DB table. | yii\ |
update() | Creates an UPDATE SQL statement. | QueryBuilder |
upsert() | Generates a MERGE statement that inserts a row or updates the matching one in a single atomic operation. | QueryBuilder |
buildAddCommentSql() protected | Builds the SQL to add or update the MS_Description extended property of a table or column. | QueryBuilder |
buildRemoveCommentSql() protected | Builds the SQL to remove the MS_Description extended property from a table or column. | QueryBuilder |
concatUnionSql() protected | Concatenates the first SELECT statement with the UNION clauses built by buildUnion(). | yii\ |
defaultConditionClasses() protected | Contains array of default condition classes. Extend this method, if you want to change default condition classes for the query builder. See $conditionClasses docs for details. | yii\ |
defaultExpressionBuilders() protected | Contains array of default expression builders. Extend this method and override it, if you want to change default expression builders for this query builder. See $expressionBuilders docs for details. | QueryBuilder |
extractAlias() protected | Extracts table alias if there is one or returns false | QueryBuilder |
hasLimit() protected | Checks to see if the given limit is effective. | yii\ |
hasOffset() protected | Checks to see if the given offset is effective. | yii\ |
prepareInsertSelectSubQuery() protected | Prepare select-subquery and field names for INSERT INTO … SELECT SQL statement. | yii\ |
prepareInsertValues() protected | Prepares a VALUES part for an INSERT SQL statement. | yii\ |
prepareSelectQuery() protected | Performs driver-specific preparation after Query::prepare(). | QueryBuilder |
prepareUpdateSets() protected | Prepares a SET parts for an UPDATE SQL statement. | yii\ |
prepareUpsertColumns() protected | yii\ | |
prepareUpsertSets() protected | Prepares the SET assignments for the update branch of an upsert statement. | yii\ |
Constants
Section titled “Constants”| Constant | Value | Description | Defined by |
|---|---|---|---|
PARAM_PREFIX | ':qp' | The prefix for automatically generated query binding parameters. | yii\ |
Method details
Section titled “Method details”addCommentOnColumn()
Section titled “addCommentOnColumn() ”public function addCommentOnColumn(mixed $table, mixed $column, mixed $comment): stringBuilds a SQL command for adding comment to column.
Parameters
| Parameter | Type | Description |
|---|---|---|
$table | mixed | The table whose column is to be commented. The table name will be properly quoted by the method. |
$column | mixed | The name of the column to be commented. The column name will be properly quoted by the method. |
$comment | mixed | The text of the comment to be added. The comment will be properly quoted by the method. |
Returns
string: The SQL statement for adding comment on column
Since
2.0.8
addCommentOnTable()
Section titled “addCommentOnTable() ”public function addCommentOnTable(mixed $table, mixed $comment): stringBuilds a SQL command for adding comment to table.
Parameters
| Parameter | Type | Description |
|---|---|---|
$table | mixed | The table whose column is to be commented. The table name will be properly quoted by the method. |
$comment | mixed | The text of the comment to be added. The comment will be properly quoted by the method. |
Returns
string: The SQL statement for adding comment on table
Since
2.0.8
addDefaultValue()
Section titled “addDefaultValue() ”public function addDefaultValue(mixed $name, mixed $table, mixed $column, mixed $value): stringCreates a SQL command for adding a default value constraint to an existing table.
Parameters
| Parameter | Type | Description |
|---|---|---|
$name | mixed | The name of the default value constraint. The name will be properly quoted by the method. |
$table | mixed | The table that the default value constraint will be added to. The name will be properly quoted by the method. |
$column | mixed | The name of the column to that the constraint will be added on. The name will be properly quoted by the method. |
$value | mixed | Default value. |
Returns
string: The SQL statement for adding a default value constraint to an existing table.
Throws
yii\base\NotSupportedException: if this is not supported by the underlying DBMS.
Since
2.0.13
alterColumn()
Section titled “alterColumn() ”public function alterColumn(string $table, string $column, string $type): stringBuilds a SQL statement for changing the definition of a column.
Drops the default, check, and unique constraints attached to the column before the ALTER COLUMN statement,
because SQL Server rejects altering a column while such constraints are bound to it. Default, check, and unique
constraints defined by a ColumnSchemaBuilder type are re-created after the column is altered.
Parameters
| Parameter | Type | Description |
|---|---|---|
$table | string | The table whose column is to be changed. The table name will be properly quoted by the method. |
$column | string | The name of the column to be changed. The name will be properly quoted by the method. |
$type | string | The new column type. The getColumnType() method will be invoked to convert abstract column type (if any) into the physical one. Anything that is not recognized as abstract type will be kept in the generated SQL. For example, ‘string’ will be turned into ‘varchar(255)’, while ‘string not null’ will become ‘varchar(255) not null’. |
Returns
string: The SQL statement for changing the definition of a column.
Throws
yii\base\NotSupportedException: if this is not supported by the underlying DBMS.
buildOrderByAndLimit()
Section titled “buildOrderByAndLimit() ”public function buildOrderByAndLimit(mixed $sql, mixed $orderBy, mixed $limit, mixed $offset): stringBuilds the ORDER BY and LIMIT/OFFSET clauses and appends them to the given SQL.
Parameters
| Parameter | Type | Description |
|---|---|---|
$sql | mixed | The existing SQL (without ORDER BY/LIMIT/OFFSET) |
$orderBy | mixed | The order by columns. See Query::orderBy() for more details on how to specify this parameter. |
$limit | mixed | The limit number. See Query::limit() for more details. |
$offset | mixed | The offset number. See Query::offset() for more details. |
Returns
string: The SQL completed with ORDER BY/LIMIT/OFFSET (if any)
buildUnionOrderByAndLimit()
Section titled “buildUnionOrderByAndLimit() ”public function buildUnionOrderByAndLimit(string $sql, array|null $orderBy, int|yii\db\ExpressionInterface|null $limit, int|yii\db\ExpressionInterface|null $offset): stringBuilds the global ORDER BY and LIMIT/OFFSET clauses for a UNION query.
Parameters
| Parameter | Type | Description |
|---|---|---|
$sql | string | The complete UNION SQL without global ORDER BY/LIMIT/OFFSET clauses. |
$orderBy | array| | The global order by columns. |
$limit | int|yii\| | The global limit. |
$offset | int|yii\| | The global offset. |
Returns
string: The completed UNION SQL.
Since
22.0
buildWithQueries()
Section titled “buildWithQueries() ”public function buildWithQueries(mixed $withs, mixed &$params): stringSQL Server does not support the RECURSIVE keyword for CTEs. Recursion is implicit when a CTE references itself.
Parameters
| Parameter | Type | Description |
|---|---|---|
$withs | mixed | Of configurations for each WITH query |
$params | mixed | The binding parameters to be populated |
Returns
string: Compiled WITH prefix of query including nested queries
Since
2.0.35
checkIntegrity()
Section titled “checkIntegrity() ”public function checkIntegrity(bool $check = true, string $schema = '', string $table = ''): stringBuilds a SQL statement for enabling or disabling integrity checks on table constraints.
Resolves the table and schema names without loading metadata, so the statement is built without opening a
database connection. A single table yields a direct ALTER TABLE statement; an empty table targets every base
table in the schema, enumerated server-side from sys.tables (views excluded) and run in one batch.
Enabling uses WITH CHECK CHECK CONSTRAINT ALL, re-validating existing rows and marking the constraints trusted;
disabling uses NOCHECK CONSTRAINT ALL.
Parameters
| Parameter | Type | Description |
|---|---|---|
$check | bool | Whether to enable (true) or disable (false) the integrity checks. |
$schema | string | The schema of the tables. Defaults to an empty string, meaning the default schema. |
$table | string | The table name. Defaults to an empty string, meaning every table in the schema. |
Returns
string: The SQL statement for enabling or disabling the integrity checks.
See also
delete()
Section titled “delete() ”public function delete(mixed $table, mixed $condition, mixed &$params): stringCreates a DELETE SQL statement.
Renders any rowversion in the WHERE condition as a binary literal, enabling optimistic-lock deletes.
For example,
$sql = $queryBuilder->delete('user', 'status = 0');The method will properly escape the table and column names.
Parameters
| Parameter | Type | Description |
|---|---|---|
$table | mixed | The table where the data will be deleted from. |
$condition | mixed | The condition that will be put in the WHERE part. Please refer to Query::where() on how to specify condition. |
$params | mixed | The binding parameters that will be modified by this method so that they can be bound to the DB command later. |
Returns
string: The DELETE SQL
See also
dropColumn()
Section titled “dropColumn() ”public function dropColumn(mixed $table, mixed $column): mixedDrop all constraints before column delete.
Parameters
| Parameter | Type | Description |
|---|---|---|
$table | mixed | |
$column | mixed |
Returns
mixed
dropCommentFromColumn()
Section titled “dropCommentFromColumn() ”public function dropCommentFromColumn(mixed $table, mixed $column): stringBuilds a SQL command for adding comment to column.
Parameters
| Parameter | Type | Description |
|---|---|---|
$table | mixed | The table whose column is to be commented. The table name will be properly quoted by the method. |
$column | mixed | The name of the column to be commented. The column name will be properly quoted by the method. |
Returns
string: The SQL statement for adding comment on column
Since
2.0.8
dropCommentFromTable()
Section titled “dropCommentFromTable() ”public function dropCommentFromTable(mixed $table): stringBuilds a SQL command for adding comment to table.
Parameters
| Parameter | Type | Description |
|---|---|---|
$table | mixed | The table whose column is to be commented. The table name will be properly quoted by the method. |
Returns
string: The SQL statement for adding comment on column
Since
2.0.8
dropDefaultValue()
Section titled “dropDefaultValue() ”public function dropDefaultValue(mixed $name, mixed $table): stringCreates a SQL command for dropping a default value constraint.
Parameters
| Parameter | Type | Description |
|---|---|---|
$name | mixed | The name of the default value constraint to be dropped. The name will be properly quoted by the method. |
$table | mixed | The table whose default value constraint is to be dropped. The name will be properly quoted by the method. |
Returns
string: The SQL statement for dropping a default value constraint.
Throws
yii\base\NotSupportedException: if this is not supported by the underlying DBMS.
Since
2.0.13
See also
getColumnType()
Section titled “getColumnType() ”public function getColumnType(mixed $type): stringConverts an abstract column type into a physical column type.
The conversion is done using the type map specified in $typeMap.
The following abstract column types are supported (using MySQL as an example to explain the corresponding
physical types):
pk: an auto-incremental primary key type, will be converted into “int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY”bigpk: an auto-incremental primary key type, will be converted into “bigint(20) NOT NULL AUTO_INCREMENT PRIMARY KEY”upk: an unsigned auto-incremental primary key type, will be converted into “int(10) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY”char: char type, will be converted into “char(1)”string: string type, will be converted into “varchar(255)”text: a long string type, will be converted into “text”smallint: a small integer type, will be converted into “smallint(6)”integer: integer type, will be converted into “int(11)”bigint: a big integer type, will be converted into “bigint(20)”boolean: boolean type, will be converted into “tinyint(1)”- `float“: float number type, will be converted into “float”
decimal: decimal number type, will be converted into “decimal”datetime: datetime type, will be converted into “datetime”timestamp: timestamp type, will be converted into “timestamp”time: time type, will be converted into “time”date: date type, will be converted into “date”money: money type, will be converted into “decimal(19,4)”binary: binary data type, will be converted into “blob”
If the abstract type contains two or more parts separated by spaces (e.g. “string NOT NULL”), then only the first part will be converted, and the rest of the parts will be appended to the converted result. For example, ‘string NOT NULL’ is converted to ‘varchar(255) NOT NULL’.
For some of the abstract types you can also specify a length or precision constraint
by appending it in round brackets directly to the type.
For example string(32) will be converted into “varchar(32)” on a MySQL database.
If the underlying DBMS does not support these kind of constraints for a type it will
be ignored.
If a type cannot be found in $typeMap, it will be returned without any change.
Parameters
| Parameter | Type | Description |
|---|---|---|
$type | mixed | Abstract column type |
Returns
string: Physical column type.
insert()
Section titled “insert() ”public function insert(mixed $table, mixed $columns, mixed &$params): stringCreates an INSERT SQL statement.
Wraps the INSERT with an OUTPUT INSERTED.* INTO @temporary_inserted block so that the inserted row
(including computed columns and IDENTITY values) can be retrieved by the caller.
For example,
$sql = $queryBuilder->insert('user', [ 'name' => 'Sam', 'age' => 30,], $params);The method will properly escape the table and column names.
Parameters
| Parameter | Type | Description |
|---|---|---|
$table | mixed | The table that new rows will be inserted into. |
$columns | mixed | The column data (name => value) to be inserted into the table or instance of Query to perform INSERT INTO … SELECT SQL statement. Passing of Query is available since version 2.0.11. |
$params | mixed | The binding parameters that will be generated by this method. They should be bound to the DB command later. |
Returns
string: The INSERT SQL
renameColumn()
Section titled “renameColumn() ”public function renameColumn(string $table, string $oldName, string $newName): stringBuilds a SQL statement for renaming a column.
Parameters
| Parameter | Type | Description |
|---|---|---|
$table | string | The table whose column is to be renamed. The name will be properly quoted by the method. |
$oldName | string | The old name of the column. The name will be properly quoted by the method. |
$newName | string | The new name of the column. The name will be properly quoted by the method. |
Returns
string: The SQL statement for renaming a DB column.
renameTable()
Section titled “renameTable() ”public function renameTable(string $oldName, string $newName): stringBuilds a SQL statement for renaming a DB table.
Parameters
| Parameter | Type | Description |
|---|---|---|
$oldName | string | The table to be renamed. The name will be properly quoted by the method. |
$newName | string | The new table name. The name will be properly quoted by the method. |
Returns
string: The SQL statement for renaming a DB table.
resetSequence()
Section titled “resetSequence() ”public function resetSequence(string $tableName, int|null $value = null): stringCreates a SQL statement for resetting the sequence value of a table’s primary key.
The sequence will be reset such that the primary key of the next new row inserted will have the specified value or the next value after the current maximum identity value.
Parameters
| Parameter | Type | Description |
|---|---|---|
$tableName | string | The name of the table whose primary key sequence will be reset. |
$value | int| | The integer value for the primary key of the next new row inserted. If this is not set, the next new row’s primary key will have the next value after the current maximum identity value. |
Returns
string: The SQL statement for resetting sequence.
Throws
yii\base\InvalidArgumentException: if the table does not exist or there is no sequence associated with the table.
See also
- https://learn.microsoft.com/en-us/sql/t-sql/database-console-commands/dbcc-checkident-transact-sql
- https://learn.microsoft.com/en-us/sql/relational-databases/system-catalog-views/sys-identity-columns-transact-sql
- https://learn.microsoft.com/en-us/sql/t-sql/functions/ident-seed-transact-sql
- https://learn.microsoft.com/en-us/sql/t-sql/functions/ident-incr-transact-sql
selectExists()
Section titled “selectExists() ”public function selectExists(mixed $rawSql): stringCreates a SELECT EXISTS() SQL statement.
Parameters
| Parameter | Type | Description |
|---|---|---|
$rawSql | mixed | The subquery in a raw form to select from. |
Returns
string: The SELECT EXISTS() SQL statement.
Since
2.0.8
update()
Section titled “update() ”public function update(mixed $table, mixed $columns, mixed $condition, mixed &$params): stringCreates an UPDATE SQL statement.
Excludes server-managed rowversion columns from the SET clause and renders any rowversion in the WHERE as a
binary literal, enabling a rowversion column to serve as the optimistic lock attribute.
Note: SQL Server regenerates the rowversion on every write and the in-memory attribute is not refreshed
afterwards; reload the record before saving the same instance again to avoid a spurious StaleObjectException.
For example,
$params = [];$sql = $queryBuilder->update('user', ['status' => 1], 'age > 30', $params);The method will properly escape the table and column names.
Parameters
| Parameter | Type | Description |
|---|---|---|
$table | mixed | The table to be updated. |
$columns | mixed | The column data (name => value) to be updated. |
$condition | mixed | The condition that will be put in the WHERE part. Please refer to Query::where() on how to specify condition. |
$params | mixed | The binding parameters that will be modified by this method so that they can be bound to the DB command later. |
Returns
string: The UPDATE SQL
See also
upsert()
Section titled “upsert() ”public function upsert(mixed $table, mixed $insertColumns, mixed $updateColumns, mixed &$params): mixedGenerates a MERGE statement that inserts a row or updates the matching one in a single atomic operation.
The WITH (HOLDLOCK) table hint serializes concurrent upserts so they cannot insert duplicate keys.
Parameters
| Parameter | Type | Description |
|---|---|---|
$table | mixed | |
$insertColumns | mixed | |
$updateColumns | mixed | |
$params | mixed |
Returns
mixed
See also
buildAddCommentSql()
Section titled “buildAddCommentSql() ”protected function buildAddCommentSql(string $comment, string $table, string|null $column = null): stringBuilds the SQL to add or update the MS_Description extended property of a table or column.
Resolves the table name without loading metadata, so the statement is assembled without opening a database connection. The comment is added when the property is absent and updated otherwise, and the extended-property routines are qualified with the catalog when the name includes one.
Parameters
| Parameter | Type | Description |
|---|---|---|
$comment | string | Comment text. Escaped and wrapped as an N'...' literal by the method. |
$table | string | Target table. May be ‘catalog-’, ‘schema-’, or bracket-qualified. |
$column | string| | Target column, or null to comment the table itself. |
Returns
string: SQL statement that adds or updates the comment.
Since
2.0.24
buildRemoveCommentSql()
Section titled “buildRemoveCommentSql() ”protected function buildRemoveCommentSql(string $table, string|null $column = null): stringBuilds the SQL to remove the MS_Description extended property from a table or column.
Resolves the table name without loading metadata, so the statement is assembled without opening a database connection. The property is dropped only when present, and the extended-property routines are qualified with the catalog when the name includes one.
Parameters
| Parameter | Type | Description |
|---|---|---|
$table | string | Target table. May be ‘catalog-’, ‘schema-’, or bracket-qualified. |
$column | string| | Target column, or null to remove the table comment. |
Returns
string: SQL statement that removes the comment.
Since
2.0.24
defaultExpressionBuilders()
Section titled “defaultExpressionBuilders() ”protected function defaultExpressionBuilders(): arrayContains array of default expression builders. Extend this method and override it, if you want to change
default expression builders for this query builder. See $expressionBuilders docs for details.
Returns
array
Since
2.0.14
extractAlias()
Section titled “extractAlias() ”protected function extractAlias(mixed $table): bool|arrayExtracts table alias if there is one or returns false
Parameters
| Parameter | Type | Description |
|---|---|---|
$table | mixed |
Returns
bool|array
Since
2.0.24
prepareSelectQuery()
Section titled “prepareSelectQuery() ”protected function prepareSelectQuery(yii\db\Query $query): yii\db\QueryPerforms driver-specific preparation after Query::prepare().
SQL Server rejects FETCH NEXT 0 and wrapping a compound query requires every result column to have a unique
name. Applying TOP (0) to every UNION operand preserves zero-row semantics without a derived table.
Implementations must not modify the given query; they must return a modified clone instead.
Parameters
| Parameter | Type | Description |
|---|---|---|
$query | yii\ | The prepared query. |
Returns
yii\db\Query: The query to build.
Since
22.0