Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQLite Select DISTINCT Values of a Column without Ordering

Tags:

I would like to know whether its possible to get a list of distinct values in a SQLite Column without ordering them.

I tried following query. But it automatically orders the unique text into ascending order.

SELECT DISTINCT column FROM table;

Ex.

Column

Mathew Mathew John John John Numbers Numbers 

Result

John Mathew Numbers 

But I would like it not to be ordered. Would like it in Mathew, John, Numbers

Thanks.

like image 411
Tharindu Madushanka Avatar asked Jan 25 '11 05:01

Tharindu Madushanka


People also ask

How do I get unique values from a column in SQLite?

Introduction to SQLite SELECT DISTINCT clause In this syntax: First, the DISTINCT clause must appear immediately after the SELECT keyword. Second, you place a column or a list of columns after the DISTINCT keyword. If you use one column, SQLite uses values in that column to evaluate the duplicate.

Can you use distinct and ORDER BY together?

Without a transformation, a statement that contains both DISTINCT and ORDER BY would require two separate sorting steps-one to satisfy DISTINCT and one to satisfy ORDER BY. (Currently, Derby uses sorting to evaluate DISTINCT.

How do I SELECT one column as distinct?

Adding the DISTINCT keyword to a SELECT query causes it to return only unique values for the specified column list so that duplicate rows are removed from the result set.

Does SELECT distinct apply to all columns?

Yes, DISTINCT works on all combinations of column values for all columns in the SELECT clause.


1 Answers

What order do you want?

If you want to get the values in the order of first appearance you can do:

select distinct column   from table  order by min(rowid); 
like image 172
Etienne Laurin Avatar answered Sep 30 '22 17:09

Etienne Laurin