views:

4505

answers:

3

I keep getting MySQL error #1054, when trying to perform this update query:

UPDATE MASTER_USER_PROFILE, TRAN_USER_BRANCH
SET MASTER_USER_PROFILE.fellow=`y`
WHERE MASTER_USER_PROFILE.USER_ID = TRAN_USER_BRANCH.USER_ID
AND TRAN_USER_BRANCH.BRANCH_ID = 17

It's probably some syntax error, but I've tried using an inner join instead and other alterations, but I keep getting the same message:

Unknown column 'y' in 'field list'

Thanks for any help.

+3  A: 

Try using different quotes for "y" as the identifier quote character is the backtick (“`”). Otherwise MySQL "thinks" that you point to a column named "y".

See also MySQL 5 Documentation

tuergeist
Thank you! I could have sworn I tried it with double quotes and single quotes, but replacing it with single quotes just now worked.
me_here
You're welcome. I suggest to read flokra's answer too ;)
tuergeist
+2  A: 

You might check your choice of quotes (use double-/ single quotes for values, strings, etc and backticks for column-names).

Since you only want to update the table master_user_profile I'd recommend a nested query:

UPDATE
   master_user_profile
SET
   master_user_profile.fellow = 'y'
WHERE
   master_user_profile.user_id IN (
      SELECT tran_user_branch.user_id
      FROM tran_user_branch WHERE tran_user_branch.branch_id = 17);

HTH, flokra

flokra
Thanks for the suggestion, that does seem like a more elegant method.
me_here
A: 

enclose any string to be passed to teh mysql server inside single quotes : ex : $name = "my name" $query = " insert into mytable values ( 1 , '$name')'

note that although the query is enclosed between double quotes , WE MUST enclose any string in single quotes.

ShoushouLeb