字符串值的SQL语法错误

时间:2015-11-10 07:25:47

标签: mysql sql

我是sql的新手,并试图弄清楚为什么我所说的区域附近有语法错误。我似乎不明白为什么我的Invoice.status的char(40)在比较字符串值时给我问号。

错误:

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use n
ear '?In Progress? AND Invoice.userId IN
                                (Select has_property.userId
                                ' at line 6

我正在尝试查找发票为“正在进行”而不是“进入”的用户的用户ID

Select User.userId, User.email
From User
Where User.userId IN (
Select Invoice.userId
From Invoice 
Where Invoice.status = ‘In Progress’ AND Invoice.userId IN
                (Select has_property.userId
                From has_property
                Where has_property.property ID 
                NOT IN
                (Select has_property.propertyID
                From has_property, home_address
                Where  House.homeAddId = home_address.homeAddId And home_address.state = ‘IN’
                 )
                )
 );

我将所有内容更改为正确的单引号,但我仍然收到错误:

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use n
ear 'userId = (Select Invoice.userIdFrom Invoice Where Invoice.status = 'In Progress'' at line 1

2 个答案:

答案 0 :(得分:1)

使用单引号'更改您使用的引号。

答案 1 :(得分:0)

这些不是真正的单引号,它们是聪明的单引号。您需要此字符:',而不是

所以,而不是

Invoice.status = ‘In Progress’

使用

Invoice.status = 'In Progress'