Here's your original request based on the column and table names you gave us:
select id, url, images, Total
from (
select *
from temp
order by id desc
limit 10
) last10
order by Total desc;
As for my pseudo-code you're confused about, that's only relevant if you have two tables that you might want to cross reference. As a more realistic example, suppose you have a database with Customers and Orders, and you want to find out your top ten buyers. You could do that like this:
select Customers.name, sales.amount -- select na
+me and total amount spent.
from Customers,
( -- a sub-sel
+ect to find the 10 best buyers.
select customer_id, sum(order_amount) as amount -- This sele
+cts 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 t
+his sub-select "sales".
where sales.customer_id = Customers.id -- we INNER
+JOIN the two "tables",
-- so we can
+ cross-reference Orders against Customers.
As you can see, the "sales" sub-select isn't a real table in the database, but within this query we can treat it as if it were. We can select columns from it, and put extra constraints on it in a where clause. I hope it's a bit clearer now :) |