From: msi77 <msi77@yandex.ru>
To: Ozer, Pam <pozer@automotive.com>
To: pgsql-sql@postgresql.org
Subject: Re: Getting top 2 by Category
Date: Tue, 11 Jan 2011 23:00:55 +0300
Message-ID: <143611294776056@web61.yandex.ru> (raw)
In-Reply-To: <216FFB77CBFAEE4B8EE4DF0A939FF1D1018440@mail-001.corp.automotive.com>
References: <216FFB77CBFAEE4B8EE4DF0A939FF1D1018440@mail-001.corp.automotive.com>
There some ways to do this in one query. Look here:
http://www.sql-ex.ru/help/select16.php
---------------
11.01.11, 22:00, "Ozer, Pam" <pozer@automotive.com>:> This is probably very simple but I am drawing a blank. Do I need to create a cursor to iterate through a table to grab the top 2 magazines per category? Here is my table and some data . The results I need are at the bottom. Any help would be greatly appreciated: CREATE TABLE magazinecategory( magazinecategoryid smallint NOT NULL , magazineid smallint, categoryid smallint); INSERT INTO magazinecategory( magazinecategoryid, magazineid, categoryid) VALUES (1, 2, 3); INSERT INTO magazinecategory( magazinecategoryid, magazineid, categoryid) VALUES (2, 8, 3); INSERT INTO magazinecategory( magazinecategoryid, magazineid, categoryid) VALUES (3 9, 3); INSERT INTO magazinecategory( magazinecategoryid, magazineid, categoryid) VALUES (4, 10, 4); INSERT INTO magazinecategory( magazinecategoryid, magazineid, categoryid) VALUES (5, 11, 4); INSERT INTO magazinecategory( magazinecategoryid, magazineid, categoryid) VALUES (6, 12,4); The results I want areCategoryID MagazineID3 23 84 104 11 Pam Ozer>
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: msi77@yandex.ru, pozer@automotive.com
Subject: Re: Getting top 2 by Category
In-Reply-To: <143611294776056@web61.yandex.ru>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox