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

前端 未结 3 1173
失恋的感觉
失恋的感觉 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: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
    

提交回复
热议问题