带有 WHERE 子句的 SQL LIMIT

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7532852/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-01 12:13:56  来源:igfitidea点击:

SQL LIMIT with WHERE clause

sqlpostgresql

提问by capdragon

Is it possible to use LIMIT x with the WHERE clause? If so, how?

是否可以将 LIMIT x 与 WHERE 子句一起使用?如果是这样,如何?

I'm trying to do this:

我正在尝试这样做:

select * from myVIew LIMIT 10 where type=3;

But i get the following error:

但我收到以下错误:

ERROR:  syntax error at or near "where"
LINE 2: where type=3;
        ^
********** Error **********
ERROR: syntax error at or near "where"
SQL state: 42601
Character: 44

回答by mr_eclair

select * from myVIew  where type=3 LIMIT 10;

Limitshould be after where clause.

Limit应该是之后where clause

Syntax :

句法 :

SELECT column_name(s)
FROM table_name
[WHERE]
LIMIT number;

回答by Adriano Carneiro

Yes, have you tried this?

是的,你试过这个吗?

select * from myVIew  where type=3 LIMIT 10;

Look here for further reference. LIMITis after WHEREand ORDER BYclauses, which makes total sense if you stop and think about it: first you have to define your base result set (filters and orders), then you limit/page it.

查看此处以获取更多参考LIMIT是 after WHEREandORDER BY子句,如果您停下来想一想,这完全有意义:首先,您必须定义基本结果集(过滤器和订单),然后对其进行限制/分页。

回答by Larry Lustig

 select * from myVIew where type=3  LIMIT 10;