Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Select every columns, but rename one of them

Tags:

sql

oracle

Let's assume I have a table named Alphabet. Now let's say this table has the following columns:

a, b, c, d, e ..., z

Now I want to select everything from the mentioned table (but select f as aaa), but I don't want to do this:

select a, b, c, d, e, f as aaa, g ..., z
from Alphabet;

Clearly the above is cumbersome if the are a lot of columns. So I am thinking if it is possible to do something like

select f as aaa, *
from Alphabet;

This is probably something there is a lot info about on the net, but I'm not sure what to search for. Has this kind of select got an expression or name? Thanks in advance

like image 367
MOR_SNOW Avatar asked Jan 13 '17 13:01

MOR_SNOW


1 Answers

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.

like image 127
Gordon Linoff Avatar answered Sep 27 '22 23:09

Gordon Linoff