简体   繁体   English

解决SQL查询结果中的歧义

[英]Resolve ambiguity in results of SQL query

Two tables have a column called "title" and so row['title'] is ambiguous and just seems to pick one of the results at random (PHP/MYSQL). 两个表具有称为“ title”的列,因此row ['title']含糊不清,似乎只是随机选择其中一个结果(PHP / MYSQL)。 Is there a way around this or do I have to make sure my columns are distinctly named even when they are in different tables? 有没有办法解决这个问题,或者即使我的列在不同的表中,我也必须确保它们的列被明确命名?

EDIT : To be clear I need the title field from BOTH tables. 编辑:要清楚,我需要两个表的标题字段。 The question is: After selecting with table1.title , table2.title How do I access them in $row as in $row = mysql_fetch_assoc($result) ? 现在的问题是:有选择后table1.titletable2.title如何访问它们在$row作为$row = mysql_fetch_assoc($result) $row['title'] is ambiguous. $row['title']不明确。 Thanks! 谢谢!

你应该能够在这种情况下使用列别名作为解释这里

Try aliasing the column: 尝试对列进行别名

SELECT A AS B
FROM TABLE

尝试这样的语法

 Select * from tableA where tableA.title=x 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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