[英]How to display a column from multiple queried tables that has same name as column in other table?
I have the following query: 我有以下查询:
SELECT a.column, b.column FROM a, b WHERE a.userid = b.id
Would like to be able to differentiate which column to display since the columns in both tables have the same name. 由于两个表中的列具有相同的名称,因此希望能够区分要显示的列。
Clearly, if I use $row['column']
it only returns one of the values. 显然,如果我使用
$row['column']
它只会返回值之一。 I have tried $row['b.column']
to differentiate the table, but that did not return anything. 我试过
$row['b.column']
来区分表,但是没有返回任何东西。
使用别名:
SELECT a.column AS aColumn, b.column AS bColumn FROM a, b WHERE a.userid = b.id
You can name the column as you want using alias "AS", eg: 您可以使用别名“ AS”为列命名,例如:
SELECT a.column AS other_name, b.column AS b_column FROM a, b WHERE a.userid = b.id
Then you can call $row['other_name']
or $row['b_column']
然后,您可以调用
$row['other_name']
或$row['b_column']
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.