SELECT结果与列的表名 [英] SELECT result with table names for columns
问题描述
一个简单的问题:
使用*
时是否可以获得MySQL结果,其表名位于列的前面,而不是仅列名?
代替:
column1, column2,
等
我需要:
table_name.column1, table_name.column2,
等
我的问题是,我连接了多个表,它们具有相同名称的列(例如,key
),但是SELECT
的结果将仅显示一个.而且,在每个连接的表中键入每一列,比简单地使用*
并随后使用表名获得结果要耗费更多的精力.
对此有什么解决办法吗?
感谢您的帮助.
我发现了另一个可以按预期工作的解决方案!
显然,至少有可能使用PHP:
$ PDO-> setAttribute(PDO :: ATTR_FETCH_TABLE_NAMES,true);
有了这个,我用完全合格的列名返回了结果. 我真的很想知道这在SQL中的外观如何,但至少可以解决问题.
由于@RobinCastlin提供了进一步的链接(将我带到了解决方案),Coulndt早就找到了它-其余的帮助!
A quick question:
Is it possible to get a MySQL result, with the tablename in front of the column instead of only the column name, when using *
?
instead of:
column1, column2,
etc
i would need:
table_name.column1, table_name.column2,
etc
My problem is, that I join multiple tables togheter, that have columns with the same name (for example, key
) but the result of the SELECT
will only show one. And typing down every single column, in every joined table, would be a lot more work than simply using *
and later get the result with Tablenames.
Is there any solution to this?
Thanks for the help.
I found another solution that actually works as expected!
Apparently, it is possible - at least, with PHP:
$PDO->setAttribute(PDO::ATTR_FETCH_TABLE_NAMES, true);
With this, I get the results back with fully-qualified Column names. I'm really wondering how this looks in SQL, but at least it solves the issue.
Coulndt find it before, thanks to @RobinCastlin for the further link (that brought me to the solution) - and to the rest, for the help!
这篇关于SELECT结果与列的表名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!