Connecting Tech Pros Worldwide Help | Site Map

SQL - work around

Member
 
Join Date: Nov 2007
Posts: 61
#1: Nov 25 '08
Expand|Select|Wrap|Line Numbers
  1. UPDATE users set user_type='CLIENT' where user_id in (SELECT user_id FROM clients)
The above query is not working with MYSQL version 4.xx, is there a work around for this.
Atli's Avatar
Moderator
 
Join Date: Nov 2006
Location: Iceland
Posts: 3,737
#2: Nov 26 '08

re: SQL - work around


You could try an INNER JOIN.

Like:
Expand|Select|Wrap|Line Numbers
  1. UPDATE userTable AS u
  2. INNER JOIN clientTable AS c
  3.     ON u.ID = c.ID
  4. SET u.UserType = 'Client';
  5.  
Member
 
Join Date: Nov 2007
Posts: 61
#3: Nov 26 '08

re: SQL - work around


Thank you Atli. But it also gives
Error:
#1064 - 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 '' at line 1
mwasif's Avatar
Moderator
 
Join Date: Jul 2006
Location: Pakistan
Posts: 718
#4: Nov 26 '08

re: SQL - work around


Try this one

Expand|Select|Wrap|Line Numbers
  1. UPDATE users, clients SET users.user_type='CLIENT' 
  2. WHERE users.user_id = clients.user_id
Atli's Avatar
Moderator
 
Join Date: Nov 2006
Location: Iceland
Posts: 3,737
#5: Nov 26 '08

re: SQL - work around


Quote:

Originally Posted by samatair View Post

Thank you Atli. But it also gives
Error:
#1064 - 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 '' at line 1

Weird. It worked for me.
I didn't use the same names as you did tho, so make sure you didn't accidentally mess up the syntax when you edited it. (Assuming you did actually edit it?)

The query mwasif posted should work to tho, and he uses that same names you did.
Try that and see what happens.
Member
 
Join Date: Nov 2007
Posts: 61
#6: Nov 27 '08

re: SQL - work around


Great! mwasif's query worked fine. Thank you very much.
Thank you too Atli for the follow up and suggestions.
You both were so helpful.

Thanks once again!
Reply