MySQL选择内部限制 [英] mysql select inside limit

查看:66
本文介绍了MySQL选择内部限制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

select
  id
from
  tableABC
limit (select count(id) from tableCBA), 1

如果我需要如示例代码所示在限制中进行选择,如何在mySql中进行选择?这只是本论坛的简化代码,否则,如果不选择,这就是复杂情况的一部分.

If I need select in limit as I have shown here in sample code, how can I do this in mySql? This is only simplified code for purpose of this forum, otherwise this is a part of sophisticated case when else select.

推荐答案

您不能直接为限制设置动态值,但是您可以在没有限制的情况下重新编写查询,如下所示:

You can't directly have a dynamic value for limit, but your query can be re-written without the limit, as follows:

set i := (select count(*) from tableCBA);
select id
from tableABC
where (i := i-1) = 0;

这将返回第n行,其中n是tableCBA中的行数;

This will return the nth row, where n is the number of rows in tableCBA;

这篇关于MySQL选择内部限制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆