0

Here is my problem. Suppose I have 3 tables namely A, B and C, each of them has a lot of columns which I do not want to list all in my query.

And here I want to do the query below:

select * from A, B, C where A.b_id = B.b_id, and B.c_id = C.c_id;

Only then I find that B and C both have a column named "kidding", so I cannot run this query due to the ambiguous column names issue.

I know that list all the column I want instead of * can handle this problem but I really do not want to do it because of the number of columns I need. So is there some smart way to handle this problem? I just need to bring all columns from A, B and C while I can set two alias for B.kidding and C.kidding.

Thanks,

qin.sun
  • 73
  • 9
  • 1
    I know of no other way aside from listing them. You can use system tables [such as](http://stackoverflow.com/questions/1526688/get-table-column-names-in-mysql) `SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = 'my_database' AND TABLE_NAME = 'my_table'`; to get a list so you don't have to type them all and then alias the needed ones. you could even write the SQL to generate the back ticks and comma's around the columns and copy/paste values to save typing. – xQbert Jan 20 '16 at 14:15
  • Well, thank you very much:D @xQbert I found my create_table.sql of A, B and C and used awk to get the column names, thank you for your help. – qin.sun Jan 20 '16 at 14:46

0 Answers0