Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When Selecting everything from MySQL can I rename specific fields and still select everything else as is with the *

Hey again guys. So, I'm trying to find out how to select every field across multiple tables in a mysql database and output the resulting table to a .csv file for Excel. I've found the infamous stackoverflow question dealing with .csv ouput and have all the code there. So, I guess what I'm asking is:

Is there a way to do a mysql query that looks something like this?

SELECT * prof.id AS youth_id FROM time time, profiles prof, WHERE foo='bar'

and have it select everything from both (or like 4) tables but select the id as youth_id, or do I have to specify EVERY value that I want if I need to select certain values as another name?

I would like to not have to specify every field as I have like 50+ to output.

I've tried to search but can't really find what I need. I guess if you could point me in the right direction that would be great.

like image 278
Ryan Avatar asked May 19 '11 23:05

Ryan


1 Answers

You don't have to specify every field. Instead you can do the following:

SELECT *, prof.id AS youth_id FROM time time, profiles prof

However the above will return all columns from the two tables plus the column you renamed. So if the original two tables have 4 columns total and you rename one, you will get 5 columns in the result set.

like image 161
secreteyes Avatar answered Sep 20 '22 07:09

secreteyes