简体   繁体   中英

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. I have tried $row['b.column'] to differentiate the table, but that did not return anything.

使用别名:

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:

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']

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM