SQL select join: is it possible to prefix all columns as 'prefix.*'?

后端 未结 22 1786
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-02 06:20

I\'m wondering if this is possible in SQL. Say you have two tables A and B, and you do a select on table A and join on table B:

SELECT a.*, b.* FROM TABLE_A a         


        
22条回答
  •  一向
    一向 (楼主)
    2020-12-02 06:59

    I am in kind of the same boat as OP - I have dozens of fields from 3 different tables that I'm joining, some of which have the same name(ie. id, name, etc). I don't want to list each field, so my solution was to alias those fields that shared a name and use select * for those that have a unique name.

    For example :

    table a : id, name, field1, field2 ...

    table b : id, name, field3, field4 ...

    select a.id as aID, a.name as aName, a. * , b.id as bID, b.name as bName, b. * .....

    When accessing the results I us the aliased names for these fields and ignore the "original" names.

    Maybe not the best solution but it works for me....i'm use mysql

提交回复
热议问题