Re: [SQL] SELECT DISTINCT

2008-02-19 Thread Richard Huxton
Shavonne Marietta Wijesinghe wrote: Hello I have 2 records with the same value. Even when i do a select with DISTINCT, it returns me both the records instead of one. SELECT DISTINCT ON (TE_COGNOME) TE_COGNOME, TE_NOME, N_GEN_TEST, TE_SESSO, TE_ATTNASC, TE_LUONASC, TE_INDI, TE_DTNASC, TE_PROVSTA

Re: [SQL] SELECT DISTINCT ... ORDER BY UPPER(column_name) fails

2007-11-04 Thread Tom Lane
Aymeric Levaux <[EMAIL PROTECTED]> writes: > SELECT DISTINCT tag FROM logs ORDER BY UPPER(tag); > You get the following error message : > for SELECT DISTINCT, ORDER BY expressions must appear in select list. > It is weird as the order by column appears in the select. No it doesn't. The ORDER BY

Re: [SQL] SELECT DISTINCT too slow

2006-06-01 Thread Florian Weimer
* Alvaro Herrera: > Miroslav ?ulc wrote: >> The GROUP BY is really fast :-) > > Doh! How does it do it? It uses a hash table and can therefore discard duplicate rows more quickly (essentially linear time in the number of rows if the number of different rows is bounded).

Re: [SQL] SELECT DISTINCT too slow

2006-06-01 Thread Miroslav Šulc
Greg Stark napsal(a): Actually you could try the equivalent query: SELECT Key FROM MRTPContactValue GROUP BY Key This may or may not be faster because it can use a hash aggregate plan. I would expect it to be faster here because there are few distinct keys and the planner predicts that.

Re: [SQL] SELECT DISTINCT too slow

2006-06-01 Thread Greg Stark
Alvaro Herrera <[EMAIL PROTECTED]> writes: > Miroslav ?ulc wrote: > > Well, "key" is not primary key from another table. It is just a column > > in pair "key" => "value". > > The structure of the table is this: > > > > Id (primary key) > > MRTPContactId (id of contact from table MRTPContact) > >

Re: [SQL] SELECT DISTINCT too slow

2006-06-01 Thread Alvaro Herrera
Miroslav ?ulc wrote: > The GROUP BY is really fast :-) Doh! How does it do it? -- Alvaro Herrerahttp://www.CommandPrompt.com/ The PostgreSQL Company - Command Prompt, Inc. ---(end of broadcast)--- TIP 1: if posting

Re: [SQL] SELECT DISTINCT too slow

2006-06-01 Thread Miroslav Šulc
The GROUP BY is really fast :-) Thank you. Miroslav Šulc Tom Lane napsal(a): > Try > SELECT Key FROM MRTPContactValue GROUP BY Key > > The "select distinct" code is a bit old and crufty, GROUP BY is usually > smarter. > > regards, tom lane > begin:vcard fn;quoted-

Re: [SQL] SELECT DISTINCT too slow

2006-06-01 Thread Tom Lane
=?ISO-8859-2?Q?Miroslav_=A9ulc?= <[EMAIL PROTECTED]> writes: > I have a table with cca 400,000 rows. The table contains column "key" of > varchar(20) type containing 10 distinct values. I want to get out what > distinct values are present in the column. I use this simple query, > which is very slow

Re: [SQL] SELECT DISTINCT too slow

2006-06-01 Thread Miroslav Šulc
It might be a good solution :-) Thank you for your help. Miroslav Šulc Alvaro Herrera napsal(a): > Miroslav ?ulc wrote: > >> Well, "key" is not primary key from another table. It is just a column >> in pair "key" => "value". >> The structure of the table is this: >> >> Id (primary key) >> MR

Re: [SQL] SELECT DISTINCT too slow

2006-06-01 Thread Alvaro Herrera
Miroslav ?ulc wrote: > Well, "key" is not primary key from another table. It is just a column > in pair "key" => "value". > The structure of the table is this: > > Id (primary key) > MRTPContactId (id of contact from table MRTPContact) > Key (key from pair key => value) > Value (value from pair ke

Re: [SQL] SELECT DISTINCT too slow

2006-06-01 Thread Miroslav Šulc
Well, "key" is not primary key from another table. It is just a column in pair "key" => "value". The structure of the table is this: Id (primary key) MRTPContactId (id of contact from table MRTPContact) Key (key from pair key => value) Value (value from pair key => value) So I want the get th

Re: [SQL] SELECT DISTINCT too slow

2006-06-01 Thread Alvaro Herrera
Miroslav ?ulc wrote: > Hello, > > I have a table with cca 400,000 rows. The table contains column "key" of > varchar(20) type containing 10 distinct values. I want to get out what > distinct values are present in the column. I use this simple query, > which is very slow: > > SELECT DISTINCT Key F

Re: [SQL] select distinct and order by

2004-04-28 Thread Stijn Vanroye
he help, Stijn Vanroye -Original Message- From: Viorel Dragomir [mailto:[EMAIL PROTECTED] Sent: woensdag 28 april 2004 11:54 To: Stijn Vanroye; [EMAIL PROTECTED] Subject: Re: [SQL] select distinct and order by I don't know if this will work, but why not try it ? :) select distinc

Re: [SQL] select distinct and order by

2004-04-28 Thread Viorel Dragomir
I don't know if this will work, but why not try it ? :)   select distinct fullname, distinct staff_id, loginname from staffwhere staff_id in   (select staff_id from staffmembership where staffgroup_id=#SomeIdValue#)order by fullname, staff_id     Next one is more complicate but with more chan

Re: [SQL] Select distinct and order by.

2001-07-17 Thread Tom Lane
Carlos <[EMAIL PROTECTED]> writes: > Select distinct field1, field2 from table1 order by field3; > The value return by PQresultErrorMessage is: > For SELECT DISTINCT, ORDER BY expressions must appear in target list > Whatever this query works fine in postgresql 6.5.3. > Is correct this query a

Re: [SQL] Select distinct and order by.

2001-07-17 Thread Tod McQuillin
On Wed, 11 Jul 2001, Carlos wrote: > Select distinct field1, field2 from table1 order by field3; > > The value return by PQresultErrorMessage is: > > For SELECT DISTINCT, ORDER BY expressions must appear in target list That's because this query is ambiguous. What if table1 looks like this: fie

Re: [SQL] SELECT DISTINCT problems

2001-02-28 Thread Richard Huxton
From: "SCAHILL KEVIN" <[EMAIL PROTECTED]> > I would like to pull each distinct value of LecturerName with any one > corresponding ProjectCode value, it does not matter what the ProjectCode > value is, but all attemps at this have failed so far. > > I have tried this but it does not work: > > Set

Re: [SQL] SELECT DISTINCT problems

2001-02-28 Thread Tom Lane
SCAHILL KEVIN <[EMAIL PROTECTED]> writes: > I have tried this but it does not work: > Set rsLecturers = Server.CreateObject("ADODB.Recordset") > sqlLect = "Select LecturerName, MIN(ProjectCode) from tblSuggestions WHERE > LecturerName IN ( SELECT DISTINCT LecturerName FROM tblSuggestions)" > rsL