There are two columns in the new table(table1 join table2) which have the same column name, how to get the values of both respectively

前端 未结 4 976
有刺的猬
有刺的猬 2021-01-26 19:05
select * from table1 join table2 on table1.column3=table2.column4 where ...
...
$row=mysql_fetch_assoc($result);

However, there are two columns in the

4条回答
  •  时光取名叫无心
    2021-01-26 19:40

    Prefix the column name in the select with its table name.

    select table1.my_column, table2.my_column
    from table1, table2
    where table1.id = table2.t1_id
    

    But with this method, you would have to read the columns using their returned order indexes, rather than their names. Another answer mentioned using as to name each column, so consider that if you're going to read them by name.

提交回复
热议问题