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

后端 未结 22 1837
爱一瞬间的悲伤
爱一瞬间的悲伤 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:35

    I solved a similar problem of mine by renaming the fields in the tables involved. Yes, I had the privilege of doing this and understand that everybody may not have it. I added prefix to each field within a table representing the table name. Thus the SQL posted by OP would remain unchanged -

    SELECT a.*, b.* FROM TABLE_A a JOIN TABLE_B b USING (some_id);
    

    and still give the expected results - ease of identifying which table the output fields belongs to.

提交回复
热议问题