0

How can I get only the first few rows, After I performed order by to a table?

In SQL 2012, let's say I have a table:

 ----------------------
| Sales | ProductType |
 ----------------------
120     | Foodstuff
100     | Electronic
200     | Mobile

Now the problem is: I select with order by Sales DESC

and I only want to get 2 rows.

Kara
  • 6,115
  • 16
  • 50
  • 57

1 Answers1

0

You can use the limit clause.

SELECT *
  FROM tablename
  ORDER BY sales DESC
  LIMIT n;

Where n is the number of rows you want to select

adanot
  • 318
  • 2
  • 21