For Custom Column Output Names Terminal MySQL, when selecting data from a table using the SELECT statement, you can customize the output column names. This can be useful when the column names in the table are not descriptive enough or when you want to format the output in a specific way.
Custom Column Output Names Terminal MySQL
To customize the output column names in MySQL, you can use the AS keyword to specify a new name for the column. The syntax for using AS is as follows:SELECT column_name AS new_column_name FROM table_name;In this syntax, "column_name" refers to the name of the column in the table and "new_column_name" refers to the name you want to give to the output column. For example, consider a table named "students" with columns "id", "name", and "age". If you want to select the name and age columns from the table, but give them more descriptive output names, you can use the following query:
SELECT name AS student_name, age AS student_age FROM students;This will output a table with columns "student_name" and "student_age" instead of "name" and "age". You can also use expressions in the AS keyword to format the output of the column. For example, if you want to concatenate the "name" and "age" columns with a space in between, you can use the following query:
SELECT CONCAT(name, ' ', age) AS student_info FROM students;This will output a column named "student_info" with the concatenated name and age values. In addition to the AS keyword, you can also use aliases to give output columns custom names. Aliases are shorthand for the AS keyword and can be used interchangeably. For example, the previous query could also be written as:
SELECT CONCAT(name, ' ', age) student_info FROM students;This will have the same output as the previous query. In conclusion, customizing output column names in MySQL can make your queries more readable and organized. By using the AS keyword or aliases, you can easily give output columns new names or format them in a specific way.
Custom column output names in terminal.
SELECT [column] AS [custom-column] FROM [table];Complete Cheat Sheet