1

There is three field in my data base id(primary key),name, salary I want fetch top 3 salary from the database.

Nidhi
  • 755
  • 3
  • 11
  • 25
  • 1
    possible duplicate of [SQLite - sorting a table](http://stackoverflow.com/questions/669964/sqlite-sorting-a-table) – Oded May 14 '10 at 08:09

4 Answers4

1

SELECT * FROM your_table ORDER BY id DESC;

jkramer
  • 15,440
  • 5
  • 47
  • 48
1
    SELECT [column(s)]
      FROM [table]
  ORDER BY [column(s)] [ASC, DESC];

For more information check here: http://www.sqlite.org/lang_select.html

Neil Knight
  • 47,437
  • 25
  • 129
  • 188
1

SQL has an ORDER BY clause that allows you do order the result set by any column/columns, ascending and descending.

For your particular question:

SELECT Id, Name
FROM myTable
ORDER BY Id DESC;

See this SO question (SQLite - sorting a table).

Community
  • 1
  • 1
Oded
  • 489,969
  • 99
  • 883
  • 1,009
1

Use LIMIT to get top 3 after ordering, as such:

SELECT *
FROM myTable
ORDER BY salary DESC
LIMIT 3;