Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL Error: Incorrect usage of UPDATE and LIMIT

How can I correct this problem so that my MySQL code works correctly.

Here is my MySQL code that gives me the problem.

$q = "UPDATE users INNER JOIN contact_info ON contact_info.user_id = users.user_id SET active.users = NULL WHERE (email.contact_info = '" . mysqli_real_escape_string($mysqli, $x) . "' AND active.users = '" . mysqli_real_escape_string($mysqli, $y) . "') LIMIT 1";
$r = mysqli_query ($mysqli, $q) or trigger_error("Query: $q\n<br />MySQL Error: " . mysqli_error($mysqli));
like image 676
HELP Avatar asked Nov 27 '10 13:11

HELP


3 Answers

As per the MySQL docs for UPDATE:

For the multiple-table syntax, UPDATE updates rows in each table named in table_references that satisfy the conditions. In this case, ORDER BY and LIMIT cannot be used.

like image 103
Marc B Avatar answered Nov 03 '22 18:11

Marc B


**if you want to update multiple rows using limit in mysql...directly limit you cant use try like this**

UPDATE table_name SET name='test'
     WHERE id IN (
         SELECT id FROM (
             SELECT id FROM table_name 
             ORDER BY id ASC  
             LIMIT 0, 10
         ) tmp
     );
like image 40
Roopchand Avatar answered Nov 03 '22 18:11

Roopchand


For the multiple-table syntax, UPDATE updates rows in each table named in table_references that satisfy the conditions. In this case, ORDER BY and LIMIT cannot be used

like image 4
Kamran Mushtaq Avatar answered Nov 03 '22 18:11

Kamran Mushtaq