MySQL别名列通配符

时间:2014-11-04 08:59:46

标签: mysql sql select wildcard

我们搜索在Collumn别名

内的mysql SELECT语句中使用通配符的可能性 像这样:

对于每一栏:

SELECT a.* as task_*, b.* as types_* 
FROM tasks AS a 
LEFT JOIN types AS b 
ON a.type_id = b.id_type 
ORDER BY a.lastmod DESC

不仅适用于显式列:

SELECT a.title as task_title, b.title as types_title 
FROM tasks AS a 
LEFT JOIN types AS b 
ON a.type_id = b.id_type 
ORDER BY a.lastmod DESC

但它没有用,有什么想法吗?

注意:作为短名称的前缀短手

a.* as prefix_*

2 个答案:

答案 0 :(得分:2)

SELECT a.* as task_完全错了。列别名适用于单列,不适用于整列列表。使用*运算符,您将从相应的表中选择所有列。您需要修改您的查询,如

SELECT a.*, b.*
FROM tasks AS a 
LEFT JOIN types AS b 
ON a.type_id = b.id_type 
ORDER BY a.lastmod DESC

(OR)显式设置选择列表中每列的列别名。根据您的评论,a.* as prefix_(*)无法完成,因为该类型的构造未构建。

答案 1 :(得分:0)

您必须明确选择每列并为每列指定别名

example: select a.emp_name as task_empame, a.location as task_location from ...