Select first 10 distinct rows in mysql
MysqlMysql 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 * ...