select id, url, images, Total from ( select * from temp order by id desc limit 10 ) last10 order by Total desc; #### select Customers.name, sales.amount -- select name and total amount spent. from Customers, ( -- a sub-select to find the 10 best buyers. select customer_id, sum(order_amount) as amount -- This selects a column and an aggregate from Orders -- from the real table Orders. group by customer_id order by amount desc limit 10 ) sales -- we name this sub-select "sales". where sales.customer_id = Customers.id -- we INNER JOIN the two "tables", -- so we can cross-reference Orders against Customers.