How to select * and rename a column?

I can easily select all my columns from the table:

SELECT * FROM foo

But if I want to rename the column barto foobar, I need to specify all the fields manually. This makes my query unstable if a new column is added to the table:

SELECT a,b,c,d,bar AS foobar FROM foo

Is it possible to write something like

SELECT *, bar AS foobar from foo
+4
source share
3 answers

Yes you can do the following:

SELECT  bar AS foobar, a.* from foo as a;

But in this case, you will get two bars: one with the name foobar, and the other with the bar as an *extract it.

+7
source

, . , , SELECT * ... . , , - , , . "*", .

, SELECT *, bar AS foobar from foo - , , .

, !

+2

select. 10 , 60% .

- .

Please check the Explain MySQL command in each case for instructions.

0
source

All Articles