Skip to content

Instantly share code, notes, and snippets.

@mazelife
Created September 16, 2013 21:22
Show Gist options
  • Save mazelife/6586773 to your computer and use it in GitHub Desktop.
Save mazelife/6586773 to your computer and use it in GitHub Desktop.
Selects 10 product/name pairs for each vendor across all vendors.
select product, url from (
select row_number() over (partition by vendor order by product desc) as r, t.* from
(select vendor.name as vendor, product.name as product, coalesce(shelf.detail_url,shelf.buy_url, null) as url from shelf
join product on product.id = shelf.product_id
join vendor on vendor.id = shelf.vendor_id) as t) as x
where x.r <= 10
@bbengfort
Copy link

Just got 200 rows in 50121 seconds for the star2.sql data dump... this is not an optimal query for big tables!

@bbengfort
Copy link

Also, wish I could do a push request!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment