Rename single column in SELECT * in SQL, select all but a column
Sorry, no, there is not a way to replace an existing column name using a SELECT *
construct as you desire.
It is always better to define columns explicitly, especially for views, and never use SELECT *
. Just use the table's DDL as a model when you create the view. That way you can alter any column definition you want (as in your question) and eliminate columns inappropriate for the view. We use this technique to mask or eliminate columns containing sensitive data like social security numbers and passwords. The link provided by marc_s in the comments is a good read.
Select every columns, but rename one of them
You can write this:
select a.f as aaa, a.*
from Alphabet a;
Note that the output set will contain both f
and aaa
. It is unclear whether this is what you want.
To remove f
from the result set, you need to list all the columns that you do want.
How can I rename a single column in a table at select?
SELECT table1.price, table2.price AS 'other_price' ...
How does one select all columns but rename some of them in one statement?
You can try something like this:
select to_char(t.created,'DD-MON-YYYY') as created,to_char(t.edited,'DD-MON-YYYY') as edited, t.* from my_table t;
How to SELECT * and rename a column?
Yes you can do the following:
SELECT bar AS foobar, a.* from foo as a;
But in this case you will get bar twice: one with name foobar
and other with bar as *
fetched it..
rename only one column during Select
you can't the way you want it , the only way is to add as duplicate column and give it alias:
select * , time_2 as time
from (select *
FROM players
where symbol=$1 and time_2 <= $2
ORDER BY time_2 desc
limit $3) temp
ORDER BY time_2 asc;
Related Topics
Saving the for Xml Auto Results to Variable in SQL
How to Subtract Two Row's Values Within Same Column Using SQL Query
SQL Query with Union in Doctrine Symfony
Row with Minimum Value of a Column
SQL Insert into with Subquery and Value
Create Unqiue Case-Insensitive Constraint on Two Varchar Fields
Connect by or Hierarchical Queries in Rdbms Other Than Oracle
Recursive Query for Bill of Materials
MySQL Error 1248 (42000): Every Derived Table Must Have Its Own Alias
T-SQL Select Get All Months Within a Range of Years
How to Concatenate Column Values into a String Using Cte
Tool for Importing CSV Files into MySQL Database
Cannot Use Alias Name in Where Clause But Can in Order By
SQL Server Default Date Time Stamp