SQL - work around

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • samatair
    New Member
    • Nov 2007
    • 61

    SQL - work around

    [code=mysql]UPDATE users set user_type='CLIE NT' where user_id in (SELECT user_id FROM clients)[/code]

    The above query is not working with MYSQL version 4.xx, is there a work around for this.
    Last edited by Atli; Nov 26 '08, 04:33 AM. Reason: Added [code] tags.
  • Atli
    Recognized Expert Expert
    • Nov 2006
    • 5062

    #2
    You could try an INNER JOIN.

    Like:
    [code=mysql]
    UPDATE userTable AS u
    INNER JOIN clientTable AS c
    ON u.ID = c.ID
    SET u.UserType = 'Client';
    [/code]

    Comment

    • samatair
      New Member
      • Nov 2007
      • 61

      #3
      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

      Comment

      • mwasif
        Recognized Expert Contributor
        • Jul 2006
        • 802

        #4
        Try this one

        [code=mysql]UPDATE users, clients SET users.user_type ='CLIENT'
        WHERE users.user_id = clients.user_id[/code]

        Comment

        • Atli
          Recognized Expert Expert
          • Nov 2006
          • 5062

          #5
          Originally posted by samatair
          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.

          Comment

          • samatair
            New Member
            • Nov 2007
            • 61

            #6
            solved

            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!

            Comment

            Working...