3
select top(10) from customer order by customer_id desc

4 Answers 4

10
select * 
from (select top 10 * from customer order by customer_id desc) a
order by  customer_id
2
  • Shouldn't it be "order by a.customer_id"?
    – Brandon
    Commented Nov 19, 2009 at 19:28
  • I dont think it is necessarry.. it is just like doing select top 10 * from customer c order by customer_id desc
    – ps.
    Commented Nov 19, 2009 at 19:40
2

This work fine in MS SQL but for MySQL we would have to go SELECT * FROM customer ORDER BY customer_id DESC LIMIT 10

2
  • I am not sure but i think in mysql it will be select * from (select * from customer order by customer_id desc limit 10) a order by customer_id or something similar.
    – ps.
    Commented Nov 19, 2009 at 21:41
  • Or you could go Select * From customer Where customer_id in (select customer_id order by customer_id desc) order by customer_id. This way you don't transfer the whole database only for the customer_id. This will depend how many records you will get back. A few you don't mind, but if you have a large recordset and many record the economy of bandwidth will be noticed :)
    – Stéphane
    Commented Nov 30, 2009 at 21:08
1

It seems you're missing the column list that you'd like retrieved from the table.

Consider:

select top(10) 
*
from customer order by customer_id desc

or

select top(10) 
customer_id, customer_name
from customer order by customer_id desc
-1

you can use: SELECT * FROM customer ORDER BY customer_id DESC LIMIT 10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.