X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 5D15F52A39 for ; Thu, 31 Mar 2005 08:15:23 +0100 (BST) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 29893-06 for ; Thu, 31 Mar 2005 07:15:18 +0000 (GMT) Received: from anchor-post-36.mail.demon.net (anchor-post-36.mail.demon.net [194.217.242.86]) by svr1.postgresql.org (Postfix) with ESMTP id 95A7453700 for ; Thu, 31 Mar 2005 08:15:18 +0100 (BST) Received: from mwynhau.demon.co.uk ([193.237.186.96] helo=mainbox.archonet.com) by anchor-post-36.mail.demon.net with esmtp (Exim 4.42) id 1DGtte-000BJi-La; Thu, 31 Mar 2005 07:15:19 +0000 Received: from [192.168.1.17] (client17.archonet.com [192.168.1.17]) by mainbox.archonet.com (Postfix) with ESMTP id EA2A517125; Thu, 31 Mar 2005 08:15:16 +0100 (BST) Message-ID: <424BA385.4010809@archonet.com> Date: Thu, 31 Mar 2005 08:15:17 +0100 From: Richard Huxton User-Agent: Mozilla Thunderbird 1.0 (X11/20041206) X-Accept-Language: en-us, en MIME-Version: 1.0 To: Robert Treat Cc: pgsql-sql@postgresql.org Subject: Re: save me from an unconstrained join References: <1112216088.28936.404.camel@camel> In-Reply-To: <1112216088.28936.404.camel@camel> Content-Type: text/plain; charset=ISO-8859-15; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.06 tagged_above=0 required=5 tests=AWL, FORGED_RCVD_HELO X-Spam-Level: X-Archive-Number: 200503/408 X-Sequence-Number: 20887 Robert Treat wrote: > It actually does what I want... but it offends my database > sensibilities... :-) > > > Heres the basics of the tables involved: > > CREATE TABLE bds_filesize ( > bds_filesize_id serial > name text NOT NULL, > byte_limit integer NOT NULL, > slots integer NOT NULL > ); > > > CREATE TABLE software ( > software_binary_id serial, > binary_file oid, > filename text, > filesize integer, > checksum text > ); > > > query: > > select > software_binary_id, min(byte_limit) > from > bds_filesize, software_binary > where > byte_limit > filesize GROUP BY software_binary_id; > > > Basically each software is assigned a "class" based on the size of its > binary into a predetermined range of classes that are defined as > relative filesizes. The above query really does work... but istm I ought > to be joining those tables somehow... any ideas? But you are joining them - via bds_filesize.byte_limit and software.fileszie. Now, it's not an equality test, but there's nothing wrong with that. You could probably do something clever with subqueries rather than using min() but it would only complicate the query afaics. -- Richard Huxton Archonet Ltd