MySQL 在mysql中选择前10个不同的行

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5422488/
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-08-31 19:17:11  来源:igfitidea点击:

Select first 10 distinct rows in mysql

mysql

提问by Urbycoz

Is there any way in MySQL to get the first 10 distinct rows of a table.

在 MySQL 中有什么方法可以获取表的前 10 行。

i.e. Something like...

即像...

SELECT TOP 10 distinct * 
FROM people 
WHERE names='SMITH'
ORDER BY names asc

However this method doesn't actually work, because it gives the error: "Syntax Error. Missing operator in query expression distinct *"

然而,这种方法实际上不起作用,因为它给出了错误:“语法错误。在查询表达式中缺少运算符 distinct *”

回答by Quassnoi

SELECT  DISTINCT *
FROM    people
WHERE   names = 'Smith'
ORDER BY
        names
LIMIT 10

回答by Nicola Cossu

SELECT * 
FROM people 
WHERE names ='SMITH'
ORDER BY names asc
limit 10

If you need add group by clause. If you search Smith you would have to sort on something else.

如果您需要添加 group by 子句。如果您搜索 Smith,则必须对其他内容进行排序。

回答by Dominic Tancredi

Try this SELECT DISTINCT 10 * ...

尝试这个 SELECT DISTINCT 10 * ...