MySQL alias shorthand?

て烟熏妆下的殇ゞ 提交于 2019-12-01 20:38:48

问题


I need to select all columns from two tables, but need to be able to differentiate between them in the result.

Is there a shorthand method of giving each column in the result an alias?

For example:

SELECT t1.* AS t1.SOMETHING
     , t2.* AS SOMETHING_ELSE 
  FROM TABLE1 
 INNER JOIN TABLE2 
    ON SOMETHING = SOMETHING_ELSE

In the results, all columns from table one would be prefixes t1, while all results from table two would be prefixes t2.

Any advice appreciated.

Thanks.


回答1:


No, you'll need to name them explicitly.




回答2:


No, ALIAS is only for single columns. The only shorthand is to remove the AS:

SELECT column_123 col FROM x

Returns col as the alias.



来源:https://stackoverflow.com/questions/2478368/mysql-alias-shorthand

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!