What is the usage of ‘AS’ in SQL?

In SQL, the AS keyword is used to specify an alias for columns or expressions in the query result.

AS keyword can be used to specify a more readable alias for columns in the query results. For example:

Retrieve the name, age, and city of customers from the customers table.

Here, the AS keyword is used to assign aliases to the customer_name column as name, the customer_age column as age, and the customer_city column as city.

The AS keyword can be used to specify an alias for a calculation result or a subquery. For example:

Retrieve the order ID, order date, total price, and calculate a 10% tax on the total price for each order from the orders table.

Here, the AS keyword is used to assign the alias “tax” to the expression (total_price * 0.1).

In summary, the AS keyword is used to specify aliases for columns or expressions in query results in order to improve readability and understanding.

bannerAds