Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I select a column using an alias

How do I perform an sql query such as this?

SELECT column_name AS alias_name FROM table_name;

Example: I want the column 'first' to be selected as 'firstname'

Table.findAll({       attributes: [id,"first"]     })     .then(function(posts) {         res.json(posts);     }) 
like image 401
Tim Arney Avatar asked Sep 18 '15 10:09

Tim Arney


People also ask

How do I use alias columns?

SQL aliases are used to give a table, or a column in a table, a temporary name. Aliases are often used to make column names more readable. An alias only exists for the duration of that query. An alias is created with the AS keyword.

Can you use alias in SELECT?

Table Alias. Table aliases can be used in SELECT lists and in the FROM clause to show the complete record or selective columns from a table. Table aliases can be used in WHERE, GROUP BY, HAVING, and ORDER BY clauses.

How do I SELECT a specific column?

Select the letter at the top to select the entire column. Or click on any cell in the column and then press Ctrl + Space.

How do I SELECT a specific column in SQL?

To select columns, choose one of the following options: Type SELECT , followed by the names of the columns in the order that you want them to appear on the report. Use commas to separate the column names.


1 Answers

Table.findAll({   attributes: ['id', ['first', 'firstName']] //id, first AS firstName }) .then(function(posts) {   res.json(posts); }); 
like image 96
Jan Aagaard Meier Avatar answered Sep 20 '22 23:09

Jan Aagaard Meier