我的数据库设置如下
vid title
1 test
2 test
1 test2
3 test
4 test
1 test3
5 test
6 test
要点是在删除最后一个版本时获取先前版本的内容。所以我想删除test
的第6版并获取它的早期版本,它将是版本5.这是什么PHP / MySQL语法?
答案 0 :(得分:3)
DELETE FROM tbl WHERE title='test' ORDER BY vid DESC LIMIT 1;
SELECT * FROM tbl WHERE title='test' ORDER BY vid DESC LIMIT 1;
答案 1 :(得分:0)
select vid from table where title='test' order by vid desc limit 2
所以你会在这两行中获得最后一个和前一个
并删除
delete from table where vid = (select max(vid) from table where title='test')
答案 2 :(得分:0)
首先删除最高版本:
delete from `table` where title = 'test' and
vid = select max(vid) from `table` where title = 'test'
然后检索“上一个”(现在是最高版本):
select * from `table` where title = 'test' and
vid = select max(vid) from `table` where title = 'test'