Select first 10 distinct rows in mysql

Mysql

Mysql Problem Overview


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

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 *"

Mysql Solutions


Solution 1 - Mysql

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

Solution 2 - Mysql

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.

Solution 3 - Mysql

Try this SELECT DISTINCT 10 * ...

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionUrbycozView Question on Stackoverflow
Solution 1 - MysqlQuassnoiView Answer on Stackoverflow
Solution 2 - MysqlNicola CossuView Answer on Stackoverflow
Solution 3 - MysqlDominic TancrediView Answer on Stackoverflow