The AS keyword in SQL is used to specify aliases, including tables, columns or derived values: specify aliases for tables to facilitate multiple references. Assign aliases to columns to explicitly reference specific columns. Specify an alias for a derived value, referencing the result of a calculation or operation.
Usage of AS keyword in SQL
In SQL statements, the AS keyword is used for tables, Column or derived value specifies an alias. It mainly has the following uses:
1. Specify an alias for the table
When you need to reference a table multiple times, you can use AS to specify an alias for it. Then use the alias to refer to it. For example:
<code class="sql">SELECT * FROM customers AS c;</code>
2. Specify aliases for columns
Similarly, you can also use AS to specify aliases for columns in query results. This is useful when a query returns multiple columns and specific columns need to be referenced explicitly. For example:
<code class="sql">SELECT customer_id AS ID, customer_name AS Name FROM customers;</code>
3. Specify an alias for the derived value
In SQL, you can use operators and functions to perform calculations and operations on data. You can specify aliases for these derived values by using AS and then reference them in queries. For example:
<code class="sql">SELECT customer_id AS ID, customer_name AS Name, DATEDIFF(NOW(), created_at) AS DaysSinceCreation FROM customers;</code>
Usage notes:
The above is the detailed content of Usage of as in sql. For more information, please follow other related articles on the PHP Chinese website!