mySQL 子查询限制

2023-05-24数据库问题
2

本文介绍了mySQL 子查询限制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

限时送ChatGPT账号..

这可能是一个简单的...我怎样才能通过这个查询实现我想要的:

从没有 id 的帖子中删除(SELECT id FROM posts order by timestamp desc limit 0, 15)

所以,简而言之,我想删除所有不在最新 15 条上的帖子.

当我尝试那个查询时,我明白了

<块引用>

MySQL 尚不支持 'LIMIT &IN/ALL/ANY/SOME 子查询

编辑

mySQL Server 版本:5.5.8mySQL 客户端版本:mysqlnd 5.0.7-dev - 091210 - $Revision: 304625 $

<块引用>

错误:#1235 - 此版本的 MySQL 尚不支持 'LIMIT &IN/ALL/ANY/SOME 子查询'

解决方案

试试这个:

删除发件人WHERE id 不在 (选择 * 从 (选择 ID发件人ORDER BY timestamp desc limit 0, 15)作为 t);

This is probably an easy one... how can I achieve what i want with this query:

delete from posts where id not in
(SELECT id FROM posts order by timestamp desc limit 0, 15)

so, to put it in a nutshell, I want to delete every post that isn't on the latest 15.

When I try that query, I get that

MySQL doesn't yet support 'LIMIT & IN/ALL/ANY/SOME subquery

EDIT

mySQL Server version: 5.5.8
mySQL Client version: mysqlnd 5.0.7-dev - 091210 - $Revision: 304625 $

Error: #1235 - This version of MySQL doesn't yet support 'LIMIT & IN/ALL/ANY/SOME subquery'

解决方案

Try this:

DELETE 
FROM posts 
WHERE id not in (
      SELECT * FROM (
            SELECT id 
            FROM posts 
            ORDER BY timestamp desc limit 0, 15
      ) 
      as t);

这篇关于mySQL 子查询限制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End

相关推荐

Mysql目录里的ibtmp1文件过大造成磁盘占满的解决办法
ibtmp1是非压缩的innodb临时表的独立表空间,通过innodb_temp_data_file_path参数指定文件的路径,文件名和大小,默认配置为ibtmp1:12M:autoextend,也就是说在文件系统磁盘足够的情况下,这个文件大小是可以无限增长的。 为了避免ibtmp1文件无止境的暴涨导致...
2025-01-02 数据库问题
151

SQL 子句“GROUP BY 1"是什么意思?意思是?
What does SQL clause quot;GROUP BY 1quot; mean?(SQL 子句“GROUP BY 1是什么意思?意思是?)...
2024-04-16 数据库问题
62

MySQL groupwise MAX() 返回意外结果
MySQL groupwise MAX() returns unexpected results(MySQL groupwise MAX() 返回意外结果)...
2024-04-16 数据库问题
13

MySQL SELECT 按组最频繁
MySQL SELECT most frequent by group(MySQL SELECT 按组最频繁)...
2024-04-16 数据库问题
16

为什么 Mysql 的 Group By 和 Oracle 的 Group by 行为不同
Why Mysql#39;s Group By and Oracle#39;s Group by behaviours are different(为什么 Mysql 的 Group By 和 Oracle 的 Group by 行为不同)...
2024-04-16 数据库问题
13

MySQL GROUP BY DateTime +/- 3 秒
MySQL GROUP BY DateTime +/- 3 seconds(MySQL GROUP BY DateTime +/- 3 秒)...
2024-04-16 数据库问题
14