Usually data is selected based upon certain criteria. Query Builder has some useful methods to specify these, the most powerful of which being `where`. It can be used in multiple ways.
...
...
@@ -250,8 +232,7 @@ In case `$search` isn't empty the following SQL will be generated:
WHERE(`status`=10)AND(`title`LIKE'%yii%')
```
`ORDER BY`
-----
### `ORDER BY`
For ordering results `orderBy` and `addOrderBy` could be used:
...
...
@@ -266,8 +247,7 @@ Here we are ordering by `id` ascending and then by `name` descending.
```
Group and Having
----------------
### `GROUP BY` and `HAVING`
In order to add `GROUP BY` to generated SQL you can use the following:
...
...
@@ -288,8 +268,7 @@ for these are similar to the ones for `where` methods group:
$query->having(['status' => $status]);
```
Limit and offset
----------------
### `LIMIT` and `OFFSET`
To limit result to 10 rows `limit` can be used:
...
...
@@ -303,8 +282,43 @@ To skip 100 fist rows use:
$query->offset(100);
```
Union
-----
### `JOIN`
The `JOIN` clauses are generated in the Query Builder by using the applicable join method:
- `innerJoin()`
- `leftJoin()`
- `rightJoin()`
This left join selects data from two related tables in one query:
```php
$query->select(['tbl_user.name AS author', 'tbl_post.title as title'])
- Enh #2240: Improved `yii\web\AssetManager::publish()`, `yii\web\AssetManager::getPublishedPath()` and `yii\web\AssetManager::getPublishedUrl()` to support aliases (vova07)
- Enh #2325: Adding support for the `X-HTTP-Method-Override` header in `yii\web\Request::getMethod()` (pawzar)
- Enh #2364: Take into account current error reporting level in error handler (gureedo)
- Enh #2409: Added support for fetching data from database in batches (nineinchnick, qiangxue)
- Enh #2417: Added possibility to set `dataType` for `$.ajax` call in yii.activeForm.js (Borales)
- Enh: Added support for using arrays as option values for console commands (qiangxue)
- Enh: Added `favicon.ico` and `robots.txt` to default application templates (samdark)