views:

320

answers:

4
select top(10) from customer order by customer_id desc
+7  A: 

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

ps
Shouldn't it be "order by a.customer_id"?
Brandon
I dont think it is necessarry.. it is just like doing select top 10 * from customer c order by customer_id desc
ps
the query above is what you want...or atleast that is what i think..
ps
sorry for that it works....
A: 
alter view view_123 as
(
select top(10) * from Country_Profile123 order by country_id desc
)

select top(10) * from view_123 order by country_id asc

first create view and then fire a query on that view... you got what you want

Sikender
Creating a view in order to do a simple query is wrong.
Ken White
i am giving solution 2 get the answer.. this answer is not wrong buddy
Sikender
+1  A: 

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
p.campbell
+1  A: 

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

Stéphane
I am not sure but i think in mysql it will beselect * from (select * from customer order by customer_id desc limit 10) a order by customer_idor something similar.
ps
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