尝试运行这四个 SQL 命令(我使用的是 MS SQL Server Management Studio 2012,连接到 SQLServer 2012 11.0):
select 'hello' from anytable
(select 'hello' from anytable)
select 'hello' from anytable order by 1
(select 'hello' from anytable order by 1)
前三个运行得很好。第四个给出错误:
Msg 156, Level 15, State 1, Line 1 Incorrect syntax near the keyword 'order'.
知道发生了什么吗?
最佳答案
通过使用括号,您表明该查询是子查询,并且不能在子查询中使用 order by 操作。
关于sql - TSQL 中的括号 - 奇怪、预期还是错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28127885/