douxunchen3498 2012-03-12 07:05
浏览 94
已采纳

什么是最有效的SELECT方法,然后立即删除它

What would be the most efficient way to SELECT this, then DELETE it immediately.

SELECT * from `usersOnline` WHERE timestamp>NOW()-INTERVAL 5 SECOND ORDER BY rand() LIMIT 1;

How could I take this same select query, but also make it delete what it selected in the most efficient way?

  • 写回答

4条回答 默认 最新

  • dps123456789 2012-03-12 07:20
    关注
    $query = 'SELECT * FROM `usersOnline` WHERE timestamp>NOW()-INTERVAL 5 SECOND ORDER BY rand() LIMIT 1;';
    $result = mysql_query($query);
    $record = mysql_fetch_assoc($result);
    $query = 'DELETE FROM `usersOnline` WHERE id = ' . $record['id'];
    mysql_query($query);
    

    with mysql, you would have to do one and then the other. you would use the key from the select result to then delete that record directly afterwards. in this example, i am assuming your primary key column is named "id". you would replace the myssql functions with whichever method you are using to access the database of course.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭