SQL Get 10 Biggest Numbers

I am trying to extract the 10 largest numbers from a table called a bonus.

But I get this error message:

Incorrect syntax near 'LIMIT' 

My code is:

 SELECT cust_nr, period1_bonus FROM bonus ORDER BY period1_bonus DESC LIMIT 10 
+4
source share
5 answers

Since this question is also noted by w / C #, I assume that you are also interested in doing it in C #. Here is the linq-to-sql equivalent of SQL code.

 public IEnumerable<Bonus> GetHighestValues() { var query = (from b in _context.bonus take 10 orderby b.period1_bonus descending select b); return query; } 

Edit - I see that the C # tag is now removed from the question. However, my answer may help you (or others).

+1
source

Try this instead:

 SELECT TOP 10 cust_nr, period1_bonus FROM bonus ORDER BY period1_bonus DESC 

LIMIT <x> is a mySQL construct, not an MSSQL construct. TOP should work for you here.

+8
source

Try SELECT TOP

 SELECT TOP 10 cust_nr, period1_bonus FROM bonus ORDER BY period1_bonus DESC 
+6
source

I'm not sure, but it will be

 SELECT TOP 10 cust_nr, period1_bonus FROM bonus ORDER BY period1_bonus DESC 

work?

Edit: lol, I think I was right (now, seeing other answers all of a sudden) +1 for @Martin for rdbms request :)

+4
source

You seem to be using SQL Server .

In TSQL syntax is:

 SELECT TOP 10 cust_nr, period1_bonus FROM bonus ORDER BY period1_bonus DESC 
+3
source

All Articles