Rename Single Column in Select * in SQL, Select All But a Column

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



Leave a reply



Submit