English 中文(简体)
SlectT and DELETE
原标题:SELECT and DELETE
  • 时间:2010-12-03 22:11:35
  •  标签:
  • java
  • mysql

我想在表格中选择第一行,顺序为time(发送),然后删除这一行文。 我不想使用两个问题,因为另一个客户有可能在删除该行之前选择该行(这将是几个从不同网络一度连接的机器)。

我认为,我可以做这样的事情。

SELECT * FROM `mytable` ORDER BY `time` LIMIT 1;
    DELETE FROM `mytable` ORDER BY `time` LIMIT 1

......但我犯了一个错误:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ; DELETE * FROM pending ORDER BY time LIMIT 1 at line 1

这样做的最佳途径是什么? 感谢。

最佳回答

您的错误信息(不同于您的问题):

DELETE * FROM pending ORDER BY time LIMIT 1

看一看你yn的错误。 删除<代码>*。 这就是说,

DELETE FROM pending ORDER BY time LIMIT 1

工作罚款。

问题回答

您必须设立一个临时表格,MySQL确实不请你从你使用的表格中删除,见本法典:

insert  tmpTable
        (id)
select  id
from    YourTable yt
order by time limit 1;

delete  
from    YourTable
where   ID in (select id from tmpTable);

你们可以像现在这样使用分座。

delete from table where id in ( select id from table order by time limit 1);

业绩是明智的,这一解决办法是多么好。 你们也许必须做分析,看看你如何工作。





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签