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

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

    In postgres, I use the json functions to instead return json objects.... then, after querying, I json_decode the fields with a _json suffix.

    IE:

    select row_to_json(tab1.*),tab1_json, row_to_json(tab2.*) tab2_json 
     from tab1
     join tab2 on tab2.t1id=tab1.id
    

    then in PHP (or any other language), I loop through the returned columns and json_decode() them if they have the "_json" suffix (also removing the suffix. In the end, I get an object called "tab1" that includes all tab1 fields, and another called "tab2" that includes all tab2 fields.

提交回复
热议问题