Nidhi
Nidhi

Reputation: 795

How can we fetch top 3 data value from database

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

Upvotes: 1

Views: 4382

Answers (4)

Stefaan Carbon
Stefaan Carbon

Reputation: 156

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

SELECT *
FROM myTable
ORDER BY salary DESC
LIMIT 3;

Upvotes: 1

Oded
Oded

Reputation: 499402

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).

Upvotes: 1

Neil Knight
Neil Knight

Reputation: 48597

    SELECT [column(s)]
      FROM [table]
  ORDER BY [column(s)] [ASC, DESC];

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

Upvotes: 1

jkramer
jkramer

Reputation: 15768

SELECT * FROM your_table ORDER BY id DESC;

Upvotes: 1

Related Questions