update tbl_user set tbl_user.Zoneid='(Select tbl_timezone.Zoneid from tbl_timezone where tbl_timezone.timezone='[UTC - 4:30] Venezuelan Standard Time')' Where tbl_user.userid='1'
运行上述查询时出现此错误
您的SQL语法有错误;检查与您的MySQL服务器版本相对应的手册,以便在[UTC - 4:30]委内瑞拉标准时间附近使用正确的语法')' tbl_user.userid =' 1''在第1行
但是当我执行
时 update tbl_user set tbl_user.Zoneid='10' Where tbl_user.userid='1';
然后它工作正常
以下查询的结果是10。
Select tbl_timezone.Zoneid from tbl_timezone where tbl_timezone.timezone='[UTC - 4:30] Venezuelan Standard Time'
我的第一个查询有什么问题。为什么我会收到错误
答案 0 :(得分:1)
您必须删除引号:
update tbl_user set tbl_user.Zoneid=(Select tbl_timezone.Zoneid from tbl_timezone where tbl_timezone.timezone='[UTC - 4:30] Venezuelan Standard Time') Where tbl_user.userid='1'
答案 1 :(得分:1)
在所有SQL方言中,单引号用于分隔字符串:
SELECT this_is_a_column, 'This is a literal string'
FROM table
此外,还有转义机制,因此您可以编写包含单引号的字符串
SELECT 'This string contains \'single\' quotes'
在你的情况下: