1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
# Basic VALUES syntax in YQL
## VALUES as a top-level operator
It lets you create a table from specified values. For example, this statement creates a table of k columns and n rows:
```yql
VALUES (expr_11, expr_12, ..., expr_1k),
(expr_21, expr_22, ..., expr_2k),
....
(expr_n1, expr_n2, ..., expr_nk);
```
This statement is totally equivalent to the following one:
```yql
SELECT expr_11, expr_12, ..., expr_1k UNION ALL
SELECT expr_21, expr_22, ..., expr_2k UNION ALL
....
SELECT expr_n1, expr_n2, ..., expr_nk;
```
#### Example
```yql
VALUES (1,2), (3,4);
```
## VALUES after FROM
VALUES can also be used in a subquery, after FROM. For example, the following two queries are equivalent:
```yql
VALUES (1,2), (3,4);
SELECT * FROM (VALUES (1,2), (3,4));
```
In all the examples above, column names are assigned by YQL and have the format `column0 ... columnN`. To assign arbitrary column names, you can use the following construct:
```yql
SELECT * FROM (VALUES (1,2), (3,4)) as t(x,y);
```
In this case, the columns will get the names `x`, `y`.
|