How to differentiate between same field names of two tables in a select query?

前端 未结 3 1160
失恋的感觉
失恋的感觉 2020-12-21 22:50

I have more than two tables in my database and all of them contains same field names like

table A           table B       table C
field1            field1            


        
相关标签:
3条回答
  • 2020-12-21 22:58

    This is an artifact of how your programming tool handles duplicated field names. If you like, you can use AS to alias field names:

    SELECT a.field1 AS a_field1, ...
    

    It should then be accessible as a_field1.

    0 讨论(0)
  • 2020-12-21 22:59

    Just write like this,

    select a.field1 as af1,a.field2 as af2,a.field3 as af3,b.field1 as bf1,b.field2 as bf2,b.field3 as bf3,c.field1 as cf1,c.field2 as cf2,c.field3 as cf3 from table A as a, table B as b,table C as c where so and so.
    
    0 讨论(0)
  • 2020-12-21 22:59

    You can alias the columns. e.g. Note: The syntax can vary depending on your DB.

    SELECT
        a.field1 `A_Field1`,
        b.field1 `B_Field1`
    
    SELECT
        a.field1 [A_Field1],
        b.field1 [B_Field1]
    
    SELECT
        a.field1 AS A_Field1,
        b.field1 AS B_Field1
    
    0 讨论(0)
提交回复
热议问题