0
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'

I get this error when i run the above query

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '[UTC - 4:30] Venezuelan Standard Time')' Where tbl_user.userid='1'' at line 1

but when I execute

 update tbl_user set tbl_user.Zoneid='10' Where tbl_user.userid='1';

then it works fine

the result of following query is 10.

Select tbl_timezone.Zoneid from tbl_timezone where tbl_timezone.timezone='[UTC - 4:30] Venezuelan Standard Time'

whats wrong with my first query. why am I getting error

2 Answers 2

1

You have to remove quotes :

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'
Sign up to request clarification or add additional context in comments.

Comments

1

In all SQL dialects, single quotes are used to delimiter strings:

SELECT this_is_a_column, 'This is a literal string'
FROM table

Additionally, there're escaping mechanism so you can write a string that contains single quotes

SELECT 'This string contains \'single\' quotes'

In your case:

  • You pretend to write code inside a string, thus is will never be executed as such.
  • You write unquoted single quotes inside a string, thus you get a syntax error.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.