In a MySQL-Table I try to update it as follows:
UPDATE MyTable SET active=2 WHERE ((active=1) AND (If the number of rows > 20 then active=2) );
I mean, the WHERE-Condition should be (active=1) and the second condition the number of rows in table should be limited to 20. Below is my wrong approach. Maybe it helps to understand what I'm trying to say or do:
UPDATE MyTable SET active=2 WHERE ( (active=1) AND
((SELECT id, @rownum:=@rownum + 1 as Row_Number from MyTable) JOIN (SELECT @rownum := 0) r)
, Row_Number>20)
In order to understand it better, I try to write the SQL-Statement like a code-snippet as follows:
if(Row_Number<20) {
// It's not interesting.
}else {
for(var i=20; i<NumberOfRecords; i++) {
active=2;
}
}
Any idea how can I write a correct MySQL-Statement in order to accomplish my intend. Thanks in advance.