Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Need to show a SQLite query in descending order

Tags:

android

sqlite

I want to make a query such that the result will be shown in indistinct descending order.

For example, assume column ID has six rows. I need an query that shows me the list of IDs indistinct descending from 6 to 1.

EDIT: Based on the first post's text, the question is how do display query results in descending order. For instance, given the IDs

ID
--
 1
 2
 3
 4
 5
 6

Desired results:

ID
--
 6
 5
 4
 3
 2
 1
like image 650
voila Avatar asked May 05 '11 15:05

voila


People also ask

How do I sort descending in SQLite?

It allows you to sort the result set based on one or more columns in ascending or descending order. In this syntax, you place the column name by which you want to sort after the ORDER BY clause followed by the ASC or DESC keyword. The ASC keyword means ascending. And the DESC keyword means descending.

How do you write a query in descending order?

The SQL ORDER BY Keyword The ORDER BY keyword is used to sort the result-set in ascending or descending order. The ORDER BY keyword sorts the records in ascending order by default. To sort the records in descending order, use the DESC keyword.

How do you keep descending order in SQL?

To change that to "descending order", specify DESC after the column name. To be explicit that it's in ascending order, specify ASC . You can specify multiple column names after ORDER BY if you want to sort by one column and then the other(s), in order.

Which SQLite clause is used to sort the data in an ascending or descending order based on one or more columns?

SQLite ORDER BY clause is used to sort the data in an ascending or descending order, based on one or more columns.


2 Answers

You can write like this:

Cursor cursor = db.rawQuery("SELECT * FROM " + TABLE_NAME+" 
                WHERE "+STATUS+" = "+"'0'" + " ORDER BY id DESC LIMIT 10", null);
return cursor ;
like image 189
Neha Sharma Avatar answered Sep 22 '22 16:09

Neha Sharma


You need to add an ORDER BY ID DESC to your select statement.

ORDER BY

like image 21
Moystard Avatar answered Sep 22 '22 16:09

Moystard