简体   繁体   English

如何显示多个与其他表中的列名称相同的查询表中的列?

[英]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.

相关问题 从多个表中获取具有相同名称的列 - get column with same name from multiple tables 如何从具有相同列名的多个表中检索数据 - How to retrieve data from multiple table having same column name 从具有相同列名 MYSQL/PHP 的引用表上的多个表中选择 - Select from multiple tables on reference table with same column name MYSQL/PHP 如何插入两个表; 一个将插入 1 行,另一个将插入多行,两个表的一列具有相同的值 - how to insert into two tables; one will insert 1 row and the other one will insert multiple rows, the two tables has one column with the same value 使用PHP从多个表中获取具有相同名称的列 - Get column with same name from multiple tables using PHP MySQL Select,多个表中具有相同名称的列,由具有相同名称的另一列排序 - MySQL Select, column with same name from multiple tables, order by another column with same name 如何从mysql php中的两个表中检索和显示相同的列名称 - How to retrieve and display the same column Name from two tables in mysql php 如何在每个表中联接2个或更多具有相同列名的表 - How to join 2 or more tables with same column name every table 如何在表的同一列的多行中从单一格式插入相同名称的多个数据 - How to insert multiple data of same name from single form in multiple row of same column of table 如何显示来自具有相同列名的两个不同表的结果 - How to display results from two different tables with the same column names
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM