sql error-“关键字'WHERE'附近的语法不正确

时间:2022-06-01 18:19:11
SELECT ship from Outcomes outer
WHERE EXIST(select ship from Outcomes inner
where inner.ship=outer.ship
)

Why am I receiving error

为什么我收到错误

"Incorrect syntax near the keyword 'WHERE"

“关键字'WHERE'附近的语法不正确

3 个解决方案

#1


2  

You should not use keywords for alias names as outer and inner which just start confusion. Also it is exists.

您不应该将别名的关键字用作外部和内部,这只会引起混淆。它也存在。

SELECT ship from Outcomes o
WHERE EXISTS
(
  select ship from Outcomes i
  where i.ship = o.ship
)

Your query also does not make much sense. You are comparing a all column values of a table with itself. The result should output all ship and you could just do

您的查询也没有多大意义。您正在比较表的所有列值与自身。结果应输出所有船只,你可以这样做

SELECT ship from Outcomes

instead.

#2


0  

SELECT ship from Outcomes o1
WHERE EXISTS(select ship from Outcomes o2
             where o2.ship = o1.ship)

Outer and inner are both reserved words. Use something else! (Or double quote them, e.g. "outer".) Also, it's EXISTS, not EXIST.

外部和内部都是保留字。用别的东西! (或者双引号,例如“外部”。)此外,它是EXISTS,而不是EXIST。

#3


-1  

outer and inner are reserved keywords. You can better use other aliases or put the names between square brackets []

外部和内部都是保留关键字。您可以更好地使用其他别名或将名称放在方括号[]之间

SELECT ship from Outcomes otr
WHERE EXIST(select ship from Outcomes inr
where inr.ship=otr.ship
)

or

SELECT ship from Outcomes [outer]
WHERE EXIST(select ship from Outcomes [inner]
where [inner].ship=[outer].ship
)

The squery bracktes only work if you are using SQL server

只有在使用SQL服务器时才能使用squery bracktes

#1


2  

You should not use keywords for alias names as outer and inner which just start confusion. Also it is exists.

您不应该将别名的关键字用作外部和内部,这只会引起混淆。它也存在。

SELECT ship from Outcomes o
WHERE EXISTS
(
  select ship from Outcomes i
  where i.ship = o.ship
)

Your query also does not make much sense. You are comparing a all column values of a table with itself. The result should output all ship and you could just do

您的查询也没有多大意义。您正在比较表的所有列值与自身。结果应输出所有船只,你可以这样做

SELECT ship from Outcomes

instead.

#2


0  

SELECT ship from Outcomes o1
WHERE EXISTS(select ship from Outcomes o2
             where o2.ship = o1.ship)

Outer and inner are both reserved words. Use something else! (Or double quote them, e.g. "outer".) Also, it's EXISTS, not EXIST.

外部和内部都是保留字。用别的东西! (或者双引号,例如“外部”。)此外,它是EXISTS,而不是EXIST。

#3


-1  

outer and inner are reserved keywords. You can better use other aliases or put the names between square brackets []

外部和内部都是保留关键字。您可以更好地使用其他别名或将名称放在方括号[]之间

SELECT ship from Outcomes otr
WHERE EXIST(select ship from Outcomes inr
where inr.ship=otr.ship
)

or

SELECT ship from Outcomes [outer]
WHERE EXIST(select ship from Outcomes [inner]
where [inner].ship=[outer].ship
)

The squery bracktes only work if you are using SQL server

只有在使用SQL服务器时才能使用squery bracktes