我的一个专栏叫。我不能改名字,因为不是我做的。 我是否允许做一些像SELECT from TableName或有一个特殊的语法,以避免SQL Server混淆?
当前回答
将列名像这样用括号括起来,from变成[from]。
select [from] from table;
也可以使用以下命令(在查询多个表时很有用):
select table.[from] from table;
其他回答
简单的解决方案
假设列名是from;因此,查询中的列名可以通过表别名引用
Select * from user u where u.from="US"
下面的方法会很有效:
SELECT DISTINCT table.from AS a FROM table
将列名像这样用括号括起来,from变成[from]。
select [from] from table;
也可以使用以下命令(在查询多个表时很有用):
select table.[from] from table;
在MySQL中,除了使用反引号('),您还可以使用UI来更改列名。右键单击表>修改表>编辑包含sql关键字>提交的列名。
select [from] from <table>
需要注意的是,上述方法在MySQL中不起作用
在Apache Drill中,使用反引号:
select `from` from table;