Error while using MAX function in update clause

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • RuthC
    New Member
    • Nov 2007
    • 33

    Error while using MAX function in update clause

    Hi
    i want to update the recorde like this
    [CODE=mysql]
    UPDATE category_shops SET category_shops_ id = (SELECT MAX(`category_s hops_id`)+1 FROM category_shops) WHERE category_shops_ id = 0 AND shop_id= 14856 AND category_id = 14
    [/CODE]

    but getting the error
    "1093 - You can't specify target table 'category_shops ' for update in FROM clause "

    please help me
    Last edited by mwasif; Jan 3 '08, 12:24 PM. Reason: Replaced [CODE] with [CODE=mysql]
  • rpnew
    New Member
    • Aug 2007
    • 189

    #2
    Originally posted by RuthC
    Hi
    i want to update the recorde like this
    Code:
    UPDATE category_shops SET category_shops_id = (SELECT MAX(`category_shops_id`)+1 FROM category_shops) WHERE category_shops_id = 0 AND shop_id= 14856 AND category_id = 14
    but getting the error
    "1093 - You can't specify target table 'category_shops ' for update in FROM clause "

    please help me

    Its because you are Updating the table which you are using in the select clause. Which is not allowed or cant be done...
    Check the following link for MySql 5.0 manual...

    Update Query for Mysql

    and read the last line before user comments.....

    same is true for MySql 5.1 and 6.0 also. check their respective manual as well.. for update queries....
    So what you can do here is use "select" clause first assign its value to some variable and then use it in "update" query... try this if it works..

    Regards,
    RP

    Comment

    • mwasif
      Recognized Expert Contributor
      • Jul 2006
      • 802

      #3
      Hi RuthC,

      Kindly use appropriate CODE tags when posting code.Checkout the Supported CODE tags.

      Comment

      • RuthC
        New Member
        • Nov 2007
        • 33

        #4
        Thanks Its Working

        Code:
            $text = "Test Text";
            $image = imagecreatetruecolor(200,45);
            $white = imagecolorallocate($image,255,255,255);
            imagefill($image,0,0,$white);
            $red = imagecolorallocate($image,255,0,0);
            $degrees = (173/strlen($text)/3.7);
            for ($i=0;$i<strlen($text);$i++) {
                $a = ($degrees*$i)+246;
                $cos = cos(deg2rad($a));
                $sin = sin(deg2rad($a));
                $x = 180;
                $y = 0;
                $xt = round($cos*($x) - $sin*($y));
                $yt = round($sin*($x) + $cos*($y));
                imagettftext($image,12,280-($a),80+$xt,200+$yt,$red,"C:/WINDOWS/Fonts/verdana.TTF",$text[$i]);
            }
            header("Content-type: image/jpeg");
            imagejpeg($image,"",100);
            imagedestroy($image);

        Comment

        Working...