<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://docs.foji.io/index.php?action=history&amp;feed=atom&amp;title=Relational_Data_-_Statements_-_Select</id>
	<title>Relational Data - Statements - Select - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://docs.foji.io/index.php?action=history&amp;feed=atom&amp;title=Relational_Data_-_Statements_-_Select"/>
	<link rel="alternate" type="text/html" href="https://docs.foji.io/index.php?title=Relational_Data_-_Statements_-_Select&amp;action=history"/>
	<updated>2026-06-13T08:11:20Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.40.1</generator>
	<entry>
		<id>https://docs.foji.io/index.php?title=Relational_Data_-_Statements_-_Select&amp;diff=2339&amp;oldid=prev</id>
		<title>Chris.Hansen: Import ClickHouse Docs: Wed Aug 28 2024 14:52:44 GMT-0400 (Eastern Daylight Time)</title>
		<link rel="alternate" type="text/html" href="https://docs.foji.io/index.php?title=Relational_Data_-_Statements_-_Select&amp;diff=2339&amp;oldid=prev"/>
		<updated>2024-08-28T18:52:44Z</updated>

		<summary type="html">&lt;p&gt;Import ClickHouse Docs: Wed Aug 28 2024 14:52:44 GMT-0400 (Eastern Daylight Time)&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;&amp;lt;code&amp;gt;SELECT&amp;lt;/code&amp;gt; queries perform data retrieval. By default, the requested data is returned to the client, while in conjunction with [https://clickhouse.com/docs/en/sql-reference/statements/insert-into INSERT INTO] it can be forwarded to a different table.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span id=&amp;quot;syntax&amp;quot;&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
== Syntax ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sql&amp;quot;&amp;gt;[WITH expr_list|(subquery)]&lt;br /&gt;
SELECT [DISTINCT [ON (column1, column2, ...)]] expr_list&lt;br /&gt;
[FROM [db.]table | (subquery) | table_function] [FINAL]&lt;br /&gt;
[SAMPLE sample_coeff]&lt;br /&gt;
[ARRAY JOIN ...]&lt;br /&gt;
[GLOBAL] [ANY|ALL|ASOF] [INNER|LEFT|RIGHT|FULL|CROSS] [OUTER|SEMI|ANTI] JOIN (subquery)|table (ON &amp;lt;expr_list&amp;gt;)|(USING &amp;lt;column_list&amp;gt;)&lt;br /&gt;
[PREWHERE expr]&lt;br /&gt;
[WHERE expr]&lt;br /&gt;
[GROUP BY expr_list] [WITH ROLLUP|WITH CUBE] [WITH TOTALS]&lt;br /&gt;
[HAVING expr]&lt;br /&gt;
[WINDOW window_expr_list]&lt;br /&gt;
[QUALIFY expr]&lt;br /&gt;
[ORDER BY expr_list] [WITH FILL] [FROM expr] [TO expr] [STEP expr] [INTERPOLATE [(expr_list)]]&lt;br /&gt;
[LIMIT [offset_value, ]n BY columns]&lt;br /&gt;
[LIMIT [n, ]m] [WITH TIES]&lt;br /&gt;
[SETTINGS ...]&lt;br /&gt;
[UNION  ...]&lt;br /&gt;
[INTO OUTFILE filename [COMPRESSION type [LEVEL level]] ]&lt;br /&gt;
[FORMAT format]&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
All clauses are optional, except for the required list of expressions immediately after &amp;lt;code&amp;gt;SELECT&amp;lt;/code&amp;gt; which is covered in more detail [[#select-clause|below]].&lt;br /&gt;
&lt;br /&gt;
Specifics of each optional clause are covered in separate sections, which are listed in the same order as they are executed:&lt;br /&gt;
&lt;br /&gt;
* [[Relational_Data_-_Statements_-_Select_-_With|WITH clause]]&lt;br /&gt;
* [[#select-clause|SELECT clause]]&lt;br /&gt;
* [[Relational_Data_-_Statements_-_Select_-_Distinct|DISTINCT clause]]&lt;br /&gt;
* [[Relational_Data_-_Statements_-_Select_-_From|FROM clause]]&lt;br /&gt;
* [[Relational_Data_-_Statements_-_Select_-_Sample|SAMPLE clause]]&lt;br /&gt;
* [[Relational_Data_-_Statements_-_Select_-_Join|JOIN clause]]&lt;br /&gt;
* [[Relational_Data_-_Statements_-_Select_-_Prewhere|PREWHERE clause]]&lt;br /&gt;
* [[Relational_Data_-_Statements_-_Select_-_Where|WHERE clause]]&lt;br /&gt;
* [[Relational_Data_-_Statements_-_Select_-_Group_By|GROUP BY clause]]&lt;br /&gt;
* [[Relational_Data_-_Statements_-_Select_-_Limit_By|LIMIT BY clause]]&lt;br /&gt;
* [[Relational_Data_-_Statements_-_Select_-_Having|HAVING clause]]&lt;br /&gt;
* [[Relational_Data_-_Statements_-_Select_-_Qualify|QUALIFY clause]]&lt;br /&gt;
* [[Relational_Data_-_Statements_-_Select_-_Limit|LIMIT clause]]&lt;br /&gt;
* [[Relational_Data_-_Statements_-_Select_-_Offset|OFFSET clause]]&lt;br /&gt;
* [[Relational_Data_-_Statements_-_Select_-_Union|UNION clause]]&lt;br /&gt;
* [[Relational_Data_-_Statements_-_Select_-_Intersect|INTERSECT clause]]&lt;br /&gt;
* [[Relational_Data_-_Statements_-_Select_-_Except|EXCEPT clause]]&lt;br /&gt;
* [[Relational_Data_-_Statements_-_Select_-_Into_Outfile|INTO OUTFILE clause]]&lt;br /&gt;
* [[Relational_Data_-_Statements_-_Select_-_Format|FORMAT clause]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span id=&amp;quot;select-clause&amp;quot;&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
== SELECT Clause ==&lt;br /&gt;
&lt;br /&gt;
[[Relational_Data_-_Syntax#syntax-expressions|Expressions]] specified in the &amp;lt;code&amp;gt;SELECT&amp;lt;/code&amp;gt; clause are calculated after all the operations in the clauses described above are finished. These expressions work as if they apply to separate rows in the result. If expressions in the &amp;lt;code&amp;gt;SELECT&amp;lt;/code&amp;gt; clause contain aggregate functions, then ClickHouse processes aggregate functions and expressions used as their arguments during the [[Relational_Data_-_Statements_-_Select_-_Group_By|GROUP BY]] aggregation.&lt;br /&gt;
&lt;br /&gt;
If you want to include all columns in the result, use the asterisk (&amp;lt;code&amp;gt;*&amp;lt;/code&amp;gt;) symbol. For example, &amp;lt;code&amp;gt;SELECT * FROM ...&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span id=&amp;quot;dynamic-column-selection&amp;quot;&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
=== Dynamic column selection ===&lt;br /&gt;
&lt;br /&gt;
Dynamic column selection (also known as a COLUMNS expression) allows you to match some columns in a result with a [https://en.wikipedia.org/wiki/RE2_(software) re2] regular expression.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sql&amp;quot;&amp;gt;COLUMNS(&amp;#039;regexp&amp;#039;)&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
For example, consider the table:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sql&amp;quot;&amp;gt;CREATE TABLE default.col_names (aa Int8, ab Int8, bc Int8) ENGINE = TinyLog&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
The following query selects data from all the columns containing the &amp;lt;code&amp;gt;a&amp;lt;/code&amp;gt; symbol in their name.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sql&amp;quot;&amp;gt;SELECT COLUMNS(&amp;#039;a&amp;#039;) FROM col_names&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;text&amp;quot;&amp;gt;┌─aa─┬─ab─┐&lt;br /&gt;
│  1 │  1 │&lt;br /&gt;
└────┴────┘&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
The selected columns are returned not in the alphabetical order.&lt;br /&gt;
&lt;br /&gt;
You can use multiple &amp;lt;code&amp;gt;COLUMNS&amp;lt;/code&amp;gt; expressions in a query and apply functions to them.&lt;br /&gt;
&lt;br /&gt;
For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sql&amp;quot;&amp;gt;SELECT COLUMNS(&amp;#039;a&amp;#039;), COLUMNS(&amp;#039;c&amp;#039;), toTypeName(COLUMNS(&amp;#039;c&amp;#039;)) FROM col_names&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;text&amp;quot;&amp;gt;┌─aa─┬─ab─┬─bc─┬─toTypeName(bc)─┐&lt;br /&gt;
│  1 │  1 │  1 │ Int8           │&lt;br /&gt;
└────┴────┴────┴────────────────┘&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Each column returned by the &amp;lt;code&amp;gt;COLUMNS&amp;lt;/code&amp;gt; expression is passed to the function as a separate argument. Also you can pass other arguments to the function if it supports them. Be careful when using functions. If a function does not support the number of arguments you have passed to it, ClickHouse throws an exception.&lt;br /&gt;
&lt;br /&gt;
For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sql&amp;quot;&amp;gt;SELECT COLUMNS(&amp;#039;a&amp;#039;) + COLUMNS(&amp;#039;c&amp;#039;) FROM col_names&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;text&amp;quot;&amp;gt;Received exception from server (version 19.14.1):&lt;br /&gt;
Code: 42. DB::Exception: Received from localhost:9000. DB::Exception: Number of arguments for function plus does not match: passed 3, should be 2.&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
In this example, &amp;lt;code&amp;gt;COLUMNS(&amp;#039;a&amp;#039;)&amp;lt;/code&amp;gt; returns two columns: &amp;lt;code&amp;gt;aa&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;ab&amp;lt;/code&amp;gt;. &amp;lt;code&amp;gt;COLUMNS(&amp;#039;c&amp;#039;)&amp;lt;/code&amp;gt; returns the &amp;lt;code&amp;gt;bc&amp;lt;/code&amp;gt; column. The &amp;lt;code&amp;gt;+&amp;lt;/code&amp;gt; operator can’t apply to 3 arguments, so ClickHouse throws an exception with the relevant message.&lt;br /&gt;
&lt;br /&gt;
Columns that matched the &amp;lt;code&amp;gt;COLUMNS&amp;lt;/code&amp;gt; expression can have different data types. If &amp;lt;code&amp;gt;COLUMNS&amp;lt;/code&amp;gt; does not match any columns and is the only expression in &amp;lt;code&amp;gt;SELECT&amp;lt;/code&amp;gt;, ClickHouse throws an exception.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span id=&amp;quot;asterisk&amp;quot;&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
=== Asterisk ===&lt;br /&gt;
&lt;br /&gt;
You can put an asterisk in any part of a query instead of an expression. When the query is analyzed, the asterisk is expanded to a list of all table columns (excluding the &amp;lt;code&amp;gt;MATERIALIZED&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;ALIAS&amp;lt;/code&amp;gt; columns). There are only a few cases when using an asterisk is justified:&lt;br /&gt;
&lt;br /&gt;
* When creating a table dump.&lt;br /&gt;
* For tables containing just a few columns, such as system tables.&lt;br /&gt;
* For getting information about what columns are in a table. In this case, set &amp;lt;code&amp;gt;LIMIT 1&amp;lt;/code&amp;gt;. But it is better to use the &amp;lt;code&amp;gt;DESC TABLE&amp;lt;/code&amp;gt; query.&lt;br /&gt;
* When there is strong filtration on a small number of columns using &amp;lt;code&amp;gt;PREWHERE&amp;lt;/code&amp;gt;.&lt;br /&gt;
* In subqueries (since columns that aren’t needed for the external query are excluded from subqueries).&lt;br /&gt;
&lt;br /&gt;
In all other cases, we do not recommend using the asterisk, since it only gives you the drawbacks of a columnar DBMS instead of the advantages. In other words using the asterisk is not recommended.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span id=&amp;quot;extreme-values&amp;quot;&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
=== Extreme Values ===&lt;br /&gt;
&lt;br /&gt;
In addition to results, you can also get minimum and maximum values for the results columns. To do this, set the &amp;#039;&amp;#039;&amp;#039;extremes&amp;#039;&amp;#039;&amp;#039; setting to 1. Minimums and maximums are calculated for numeric types, dates, and dates with times. For other columns, the default values are output.&lt;br /&gt;
&lt;br /&gt;
An extra two rows are calculated – the minimums and maximums, respectively. These extra two rows are output in &amp;lt;code&amp;gt;XML&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;JSON*&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;TabSeparated*&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;CSV*&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;Vertical&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;Template&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;Pretty*&amp;lt;/code&amp;gt; [https://clickhouse.com/docs/en/interfaces/formats formats], separate from the other rows. They are not output for other formats.&lt;br /&gt;
&lt;br /&gt;
In &amp;lt;code&amp;gt;JSON*&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;XML&amp;lt;/code&amp;gt; formats, the extreme values are output in a separate ‘extremes’ field. In &amp;lt;code&amp;gt;TabSeparated*&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;CSV*&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;Vertical&amp;lt;/code&amp;gt; formats, the row comes after the main result, and after ‘totals’ if present. It is preceded by an empty row (after the other data). In &amp;lt;code&amp;gt;Pretty*&amp;lt;/code&amp;gt; formats, the row is output as a separate table after the main result, and after &amp;lt;code&amp;gt;totals&amp;lt;/code&amp;gt; if present. In &amp;lt;code&amp;gt;Template&amp;lt;/code&amp;gt; format the extreme values are output according to specified template.&lt;br /&gt;
&lt;br /&gt;
Extreme values are calculated for rows before &amp;lt;code&amp;gt;LIMIT&amp;lt;/code&amp;gt;, but after &amp;lt;code&amp;gt;LIMIT BY&amp;lt;/code&amp;gt;. However, when using &amp;lt;code&amp;gt;LIMIT offset, size&amp;lt;/code&amp;gt;, the rows before &amp;lt;code&amp;gt;offset&amp;lt;/code&amp;gt; are included in &amp;lt;code&amp;gt;extremes&amp;lt;/code&amp;gt;. In stream requests, the result may also include a small number of rows that passed through &amp;lt;code&amp;gt;LIMIT&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span id=&amp;quot;notes&amp;quot;&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
=== Notes ===&lt;br /&gt;
&lt;br /&gt;
You can use synonyms (&amp;lt;code&amp;gt;AS&amp;lt;/code&amp;gt; aliases) in any part of a query.&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;GROUP BY&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;ORDER BY&amp;lt;/code&amp;gt;, and &amp;lt;code&amp;gt;LIMIT BY&amp;lt;/code&amp;gt; clauses can support positional arguments. To enable this, switch on the [https://clickhouse.com/docs/en/operations/settings/settings#enable-positional-arguments enable_positional_arguments] setting. Then, for example, &amp;lt;code&amp;gt;ORDER BY 1,2&amp;lt;/code&amp;gt; will be sorting rows in the table on the first and then the second column.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span id=&amp;quot;implementation-details&amp;quot;&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
== Implementation Details ==&lt;br /&gt;
&lt;br /&gt;
If the query omits the &amp;lt;code&amp;gt;DISTINCT&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;GROUP BY&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;ORDER BY&amp;lt;/code&amp;gt; clauses and the &amp;lt;code&amp;gt;IN&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;JOIN&amp;lt;/code&amp;gt; subqueries, the query will be completely stream processed, using O(1) amount of RAM. Otherwise, the query might consume a lot of RAM if the appropriate restrictions are not specified:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;max_memory_usage&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;max_rows_to_group_by&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;max_rows_to_sort&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;max_rows_in_distinct&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;max_bytes_in_distinct&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;max_rows_in_set&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;max_bytes_in_set&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;max_rows_in_join&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;max_bytes_in_join&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;max_bytes_before_external_sort&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;max_bytes_before_external_group_by&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For more information, see the section “Settings”. It is possible to use external sorting (saving temporary tables to a disk) and external aggregation.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span id=&amp;quot;select-modifiers&amp;quot;&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
== SELECT modifiers ==&lt;br /&gt;
&lt;br /&gt;
You can use the following modifiers in &amp;lt;code&amp;gt;SELECT&amp;lt;/code&amp;gt; queries.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span id=&amp;quot;apply&amp;quot;&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
=== APPLY ===&lt;br /&gt;
&lt;br /&gt;
Allows you to invoke some function for each row returned by an outer table expression of a query.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Syntax:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sql&amp;quot;&amp;gt;SELECT &amp;lt;expr&amp;gt; APPLY( &amp;lt;func&amp;gt; ) FROM [db.]table_name&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Example:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sql&amp;quot;&amp;gt;CREATE TABLE columns_transformers (i Int64, j Int16, k Int64) ENGINE = MergeTree ORDER by (i);&lt;br /&gt;
INSERT INTO columns_transformers VALUES (100, 10, 324), (120, 8, 23);&lt;br /&gt;
SELECT * APPLY(sum) FROM columns_transformers;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;┌─sum(i)─┬─sum(j)─┬─sum(k)─┐&lt;br /&gt;
│    220 │     18 │    347 │&lt;br /&gt;
└────────┴────────┴────────┘&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;span id=&amp;quot;except&amp;quot;&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
=== EXCEPT ===&lt;br /&gt;
&lt;br /&gt;
Specifies the names of one or more columns to exclude from the result. All matching column names are omitted from the output.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Syntax:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sql&amp;quot;&amp;gt;SELECT &amp;lt;expr&amp;gt; EXCEPT ( col_name1 [, col_name2, col_name3, ...] ) FROM [db.]table_name&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Example:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sql&amp;quot;&amp;gt;SELECT * EXCEPT (i) from columns_transformers;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;┌──j─┬───k─┐&lt;br /&gt;
│ 10 │ 324 │&lt;br /&gt;
│  8 │  23 │&lt;br /&gt;
└────┴─────┘&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;span id=&amp;quot;replace&amp;quot;&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
=== REPLACE ===&lt;br /&gt;
&lt;br /&gt;
Specifies one or more [[Relational_Data_-_Syntax#syntax-expression_aliases|expression aliases]]. Each alias must match a column name from the &amp;lt;code&amp;gt;SELECT *&amp;lt;/code&amp;gt; statement. In the output column list, the column that matches the alias is replaced by the expression in that &amp;lt;code&amp;gt;REPLACE&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
This modifier does not change the names or order of columns. However, it can change the value and the value type.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Syntax:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sql&amp;quot;&amp;gt;SELECT &amp;lt;expr&amp;gt; REPLACE( &amp;lt;expr&amp;gt; AS col_name) from [db.]table_name&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Example:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sql&amp;quot;&amp;gt;SELECT * REPLACE(i + 1 AS i) from columns_transformers;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;┌───i─┬──j─┬───k─┐&lt;br /&gt;
│ 101 │ 10 │ 324 │&lt;br /&gt;
│ 121 │  8 │  23 │&lt;br /&gt;
└─────┴────┴─────┘&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;span id=&amp;quot;modifier-combinations&amp;quot;&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
=== Modifier Combinations ===&lt;br /&gt;
&lt;br /&gt;
You can use each modifier separately or combine them.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Examples:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
Using the same modifier multiple times.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sql&amp;quot;&amp;gt;SELECT COLUMNS(&amp;#039;[jk]&amp;#039;) APPLY(toString) APPLY(length) APPLY(max) from columns_transformers;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;┌─max(length(toString(j)))─┬─max(length(toString(k)))─┐&lt;br /&gt;
│                        2 │                        3 │&lt;br /&gt;
└──────────────────────────┴──────────────────────────┘&amp;lt;/pre&amp;gt;&lt;br /&gt;
Using multiple modifiers in a single query.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sql&amp;quot;&amp;gt;SELECT * REPLACE(i + 1 AS i) EXCEPT (j) APPLY(sum) from columns_transformers;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;┌─sum(plus(i, 1))─┬─sum(k)─┐&lt;br /&gt;
│             222 │    347 │&lt;br /&gt;
└─────────────────┴────────┘&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;span id=&amp;quot;settings-in-select-query&amp;quot;&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
== SETTINGS in SELECT Query ==&lt;br /&gt;
&lt;br /&gt;
You can specify the necessary settings right in the &amp;lt;code&amp;gt;SELECT&amp;lt;/code&amp;gt; query. The setting value is applied only to this query and is reset to default or previous value after the query is executed.&lt;br /&gt;
&lt;br /&gt;
Other ways to make settings see [https://clickhouse.com/docs/en/operations/settings here].&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Example&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sql&amp;quot;&amp;gt;SELECT * FROM some_table SETTINGS optimize_read_in_order=1, cast_keep_nullable=1;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
[[Category:Relational_Data]]&lt;/div&gt;</summary>
		<author><name>Chris.Hansen</name></author>
	</entry>
</feed>