Re: [GENERAL] A select DISTINCT query? - followup Q

2008-01-28 Thread Gregory Stark
"Harald Fuchs" <[EMAIL PROTECTED]> writes: > If you want to select both columns, but have uniqueness over the first > only, you can use a derived table: > > SELECT tbl.name, tbl.comment > FROM tbl > JOIN (SELECT name FROM tbl GROUP BY name HAVING count(*) = 1) AS t > ON t.name = tbl.name > Or u

Re: [GENERAL] A select DISTINCT query? - followup Q

2008-01-28 Thread Harald Fuchs
In article <[EMAIL PROTECTED]>, Phil Rhoades <[EMAIL PROTECTED]> writes: > People, >> select count(*) as cnt, name from tst group by name having count(*) = 1 > This worked for my basic example but not for my actual problem - I get > "column comment must appear in the GROUP BY clause or be used i

Re: [GENERAL] A select DISTINCT query? - followup Q

2008-01-27 Thread Phil Rhoades
Mike, I can't do that with my comments - I get all six of the records in the result with the example instead of just four like I want . . but someone else had a solution without using the "group by" clause . . Phil. On Sun, 2008-01-27 at 13:56 -0500, Mike Ginsburg wrote: > Hi Phil, > Each of

Re: [GENERAL] A select DISTINCT query? - followup Q

2008-01-27 Thread Tom Lane
johnf <[EMAIL PROTECTED]> writes: > On Sunday 27 January 2008 10:56:18 am Mike Ginsburg wrote: >> Each of columns that you specify in your SELECT clause, must also >> appear in the GROPU BY clause. > Is the requirement of select fields matching group by fields a SQL92 > requirement or something t

Re: [GENERAL] A select DISTINCT query? - followup Q

2008-01-27 Thread johnf
On Sunday 27 January 2008 10:56:18 am Mike Ginsburg wrote: > Hi Phil, > Each of columns that you specify in your SELECT clause, must also > appear in the GROPU BY clause. > > SELECT COUNT(*) AS cnt, name, comment, ... > FROM tst > GROUP BY name, comment, ... > HAVING COUNT(*) = 1; > Is the requir

Re: [GENERAL] A select DISTINCT query? - followup Q

2008-01-27 Thread Mike Ginsburg
Hi Phil, Each of columns that you specify in your SELECT clause, must also appear in the GROPU BY clause. SELECT COUNT(*) AS cnt, name, comment, ... FROM tst GROUP BY name, comment, ... HAVING COUNT(*) = 1; Phil Rhoades wrote: People, select count(*) as cnt, name from tst group by nam

Re: [GENERAL] A select DISTINCT query? - followup Q

2008-01-27 Thread Phil Rhoades
People, > select count(*) as cnt, name from tst group by name having count(*) = 1 This worked for my basic example but not for my actual problem - I get "column comment must appear in the GROUP BY clause or be used in an aggregate function" errors so I have a related question: With table: nam

Re: [GENERAL] A select DISTINCT query?

2008-01-27 Thread Phil Rhoades
Guys, On Sun, 2008-01-27 at 17:38 +0100, Pavel Stehule wrote: > On 27/01/2008, Phil Rhoades <[EMAIL PROTECTED]> wrote: > > Tino, > > > > > > On Sun, 2008-01-27 at 15:16 +0100, Tino Wildenhain wrote: > > > Phil Rhoades wrote: > > > > People, > > > > > > > > I want to select from a table ONLY uniqu

Re: [GENERAL] A select DISTINCT query?

2008-01-27 Thread Pavel Stehule
On 27/01/2008, Phil Rhoades <[EMAIL PROTECTED]> wrote: > Tino, > > > On Sun, 2008-01-27 at 15:16 +0100, Tino Wildenhain wrote: > > Phil Rhoades wrote: > > > People, > > > > > > I want to select from a table ONLY unique records ie if a column has > > > values: > > > > > > 1 > > > 2 > > > 3 > > > 3 >

Re: [GENERAL] A select DISTINCT query?

2008-01-27 Thread hubert depesz lubaczewski
On Mon, Jan 28, 2008 at 03:32:18AM +1100, Phil Rhoades wrote: > SELECT count(*) as cnt, name FRoM tst GROUP BY name HAVING cnt = 1 ; > ERROR: column "cnt" does not exist > LINE 1: ...ount(*) as cnt, name FRoM tst GROUP BY name HAVING cnt = 1 ; having count(*) = 1; depesz -- quicksil1er: "postg

Re: [GENERAL] A select DISTINCT query?

2008-01-27 Thread Phil Rhoades
Tino, On Sun, 2008-01-27 at 15:16 +0100, Tino Wildenhain wrote: > Phil Rhoades wrote: > > People, > > > > I want to select from a table ONLY unique records ie if a column has > > values: > > > > 1 > > 2 > > 3 > > 3 > > 4 > > 5 > > > > I want ONLY these records returned: > > > > 1 > > 2 > > 4

Re: [GENERAL] A select DISTINCT query?

2008-01-27 Thread Phil Rhoades
Pavel, You didn't read my note properly - your query gives: 1 2 3 4 5 I want: 1 2 4 5 Phil. On Sun, 2008-01-27 at 15:10 +0100, Pavel Stehule wrote: > Hello > > try > > SELECT DISTINCT col FROM table > > Pavel > > On 27/01/2008, Phil Rhoades <[EMAIL PROTECTED]> wrote: > > People, > > > >

Re: [GENERAL] A select DISTINCT query?

2008-01-27 Thread Tino Wildenhain
Phil Rhoades wrote: People, I want to select from a table ONLY unique records ie if a column has values: 1 2 3 3 4 5 I want ONLY these records returned: 1 2 4 5 SELECT count(*) as cnt,a,b,c FORM yourtable GROUP BY a,b,c HAVING cnt=1 should do. Regards Tino ---(en

Re: [GENERAL] A select DISTINCT query?

2008-01-27 Thread Pavel Stehule
Hello try SELECT DISTINCT col FROM table Pavel On 27/01/2008, Phil Rhoades <[EMAIL PROTECTED]> wrote: > People, > > I want to select from a table ONLY unique records ie if a column has > values: > > 1 > 2 > 3 > 3 > 4 > 5 > > I want ONLY these records returned: > > 1 > 2 > 4 > 5 > > Thanks, > >

[GENERAL] A select DISTINCT query?

2008-01-27 Thread Phil Rhoades
People, I want to select from a table ONLY unique records ie if a column has values: 1 2 3 3 4 5 I want ONLY these records returned: 1 2 4 5 Thanks, Phil. -- Philip Rhoades Pricom Pty Limited (ACN 003 252 275 ABN 91 003 252 275) GPO Box 3411 Sydney NSW 2001 Australia Fax: +61:(0)