X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 013C49DD741 for ; Fri, 2 Dec 2005 13:15:36 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 25733-10 for ; Fri, 2 Dec 2005 13:15:34 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from ermsgsvr.werh.noaa.gov (ermsgsvr.werh.noaa.gov [198.206.32.50]) by postgresql.org (Postfix) with ESMTP id 2F1A69DD725 for ; Fri, 2 Dec 2005 13:15:34 -0400 (AST) Received: from [198.206.42.50] (hopper.wiln.noaa.gov [198.206.42.50]) by ermsgsvr.werh.noaa.gov (iPlanet Messaging Server 5.2 HotFix 2.01 (built Aug 26 2004)) with ESMTPSA id <0IQV009UFRXUPI@ermsgsvr.werh.noaa.gov> for pgsql-sql@postgresql.org; Fri, 02 Dec 2005 12:15:32 -0500 (EST) Date: Fri, 02 Dec 2005 12:15:29 -0500 From: Mark Fenbers Subject: Just 1 in a series... To: PostgreSQL - SQL Message-id: <43908131.9060403@noaa.gov> Organization: DOC/NOAA/NWS/OHRFC MIME-version: 1.0 Content-type: text/plain; charset=ISO-8859-1; format=flowed Content-transfer-encoding: 7BIT X-Accept-Language: en-us, en User-Agent: Mozilla Thunderbird 1.0.7 (Windows/20050923) X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.583 required=5 tests=[AWL=0.583] X-Spam-Score: 0.583 X-Spam-Level: X-Archive-Number: 200512/6 X-Sequence-Number: 23548 I currently have a working SQL that SELECTs all records whose 'river_stage' column exceeds the 'flood_stage' column. (Very simple -- no applause needed.) Typically, if I get one record, I get a consecutive series of them since rivers rise and fall in a continuous fashion, and usually respond lethargically when this much water is in the rivers. This time-series of river stages all have (another column called) 'event_id' set to the same integer value, so long as the river has not fallen below flood stage (which will trigger the event_ID to be incremented). However, I only want the first occurrence of a such a series (where the event_id is the same), what SQL syntax should I use to do this? I tried playing with different combinations using DISTINCT, GROUP BY, and LIMIT 1, but I have had no success getting the results I'm looking for, thus far. So I figured I might get farther faster by asking the group. I must be misunderstanding the "GROUP BY" clause because I get an error essentially stating that I need to list every column in the SELECT list in the GROUP BY list (which makes it ineffective)... My knots are tangled. Can someone please send advice regarding this issue? Mark