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); })
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.
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.
Select the letter at the top to select the entire column. Or click on any cell in the column and then press Ctrl + Space.
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.
Table.findAll({ attributes: ['id', ['first', 'firstName']] //id, first AS firstName }) .then(function(posts) { res.json(posts); });
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With