![]() ![]() ![]() Note that the AS keyword is entirely optional when using aliases. The column customer_name is shown as name. The column customer_id now appears as id. Pay special attention to the column names and you will notice the impact of our aliases. The query below now contains an alias for two columns:Ĭompare this with the result from our previous example. We could write the following query:Įxecuting this query will return this result set: customer_id Imagine we wanted to see which customers are under the age of 60. We’ll use the following table, which contains basic information about our customers: customer_idįirst, we’ll use a query that does not have aliases for the column names. Renaming Columns Using AliasesĪn alias can be used to rename the columns in your SQL query. Now, let’s take a closer look at using aliases, starting with columns. Other important SQL terms are detailed in this article, SQL Terms Beginners Should Know. When working with multiple tables, it is a good practice to prefix all column names with an alias so you can easily see which column belongs to which table.īy the way, aliases are just one term that SQL users should know.An SQL alias is also handy when using a self-join.Aliases are useful when we are working with JOIN operations or aggregate functions like COUNT() and SUM().This makes the SQL query clearer and easier to understand. Complex column and table names can be simplified or given a more suitable name.Here are several reasons why you might consider using an SQL alias: ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |