MySql SELECT AS-附加所有字段名称 [英] MySql SELECT AS - Append all field names
问题描述
我想做这样的事情:
SELECT table.id AS prefix_id, table.name AS prefix_name
...,并且将前缀动态添加到所有字段名称中,而不是手动选择所有前缀(即SELECT table.* AS prefix_*
之类的东西)
... and have the prefix added dynamically to all field names rather than selecting them all manually (ie SELECT table.* AS prefix_*
or something)
希望我已经准确地描述了这一点.有什么想法吗?
Hopefully I've described that accurately. Any thoughts?
修改
要清楚,我要问的原因是要确保我的查询结果包含我调用的每个表的每一个列,即使字段名称重复也是如此.例如,我可能有一个包含很多字段的表,这意味着我不想手动为所有字段加上别名.此外,如果3个表具有名为name
的字段,我的结果将不包含三个name
结果;它会有一个. 我想避免与我的列名产生歧义.
To be clear, the reason I'm asking is to make sure that my query result contains every column from each table I call even if there are duplicate field names. For example, I might have a table with lots of fields which means I don't want to alias all the fields manually. Further if 3 tables have a field called name
my result won't contain three name
results; it will have one. I want to avoid ambiguity with my column names.
推荐答案
为避免在具有多个表的列中出现歧义,您必须手动指定多个表中具有相同名称的每个列名.
To avoid ambiguity in columns with multiple tables it appears you must manually specify each column name that exists with the same name in more than one table.
http://dev.mysql.com/doc /refman/5.0/en/identifier-qualifiers.html
这篇关于MySql SELECT AS-附加所有字段名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!