开发者

Is there MySQL offsest for update?

I have a table without primary key or unique key.

I want to update some values in nth records which order by date.

there is no offset for mysql upda开发者_StackOverflow中文版te limit( like limit 1,2), how can I do this?


UPDATE table_name
...
WHERE ids in ( SELECT ids FROM table_name limit ....)


This is ugly, but...

Can you create a temporary table? I'd suggest creating a temp table using the sorted values of the date field, selecting with the LIMIT clause. You can then update the original table using the values in the temporary table.

It would be something like this:

create temporary table temp 
  select date_field from mytable order by date_field limit 4,2;

update mytable set another_field='FOUND' 
 where date_field in (select date_field from temp);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜