Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Select first 10 distinct rows in mysql

Tags:

mysql

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

like image 898
Urbycoz Avatar asked Mar 24 '11 16:03

Urbycoz


People also ask

How do I select top 10 rows in MySQL?

To select first 10 elements from a database using SQL ORDER BY clause with LIMIT 10. Insert some records in the table using insert command. Display all records from the table using select statement. Here is the alternate query to select first 10 elements.

How do I select distinct rows in MySQL?

To get unique or distinct values of a column in MySQL Table, use the following SQL Query. SELECT DISTINCT(column_name) FROM your_table_name; You can select distinct values for one or more columns.

How do I get top 10 distinct records in SQL Server?

To do so, select Query -> Include Actual Query Plan from the menu before executing the query. The “Stream Aggregate” icon is for the DISTINCT operation and “Top” for the TOP 10 one. It may seem somewhat counterintuitive to see DISTINCT listed first within the SELECT statement.


1 Answers

SELECT  DISTINCT * FROM    people WHERE   names = 'Smith' ORDER BY         names LIMIT 10 
like image 126
Quassnoi Avatar answered Sep 24 '22 18:09

Quassnoi