Search Postgresql Archives

Select first ten of each category?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I'm stumped on this one... 

I have a table defined thusly: 

create table items ( 
id serial, 
category integer not null references category(id), 
name varchar not null, 
price real, 
unique(category, name)); 

It has a LARGE number of entries. I'd like to grab the 10 most expensive items 
from each category in a single query. How can this be done? Something like 

Select items.* 
FROM items 
where id IN (
	select firstTen(id) FROM items 
	group by category
	ORDER BY price DESC
	) 
ORDER BY price desc; 

But I've not found any incantation to make this idea work... 

-Ben 
-- 
"The best way to predict the future is to invent it."
- XEROX PARC slogan, circa 1978


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux