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

[SQL] SELECT DISTINCT

2008-02-19 Thread Shavonne Marietta Wijesinghe
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_PROVSTATO, TE_PROV, TE_PATERNITA, TE_RICH

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

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

2007-11-04 Thread Aymeric Levaux
On pgsql 8.2, if you do the following query, everything is fine: SELECT DISTINCT tag FROM logs ORDER BY tag; But if you'd like to do a case insensitive order by like this: SELECT DISTINCT tag FROM logs ORDER BY UPPER(tag); or SELECT DISTINCT tag FROM logs ORDER BY LOWER(tag); You get the fol

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

[SQL] SELECT DISTINCT too slow

2006-06-01 Thread Miroslav Šulc
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 FROM MRTPContactValue Here is the

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
know :) - Original Message - From: Stijn Vanroye To: [EMAIL PROTECTED] Sent: Wednesday, April 28, 2004 12:27 Subject: [SQL] select distinct and order by Hello everybody,I have a short question:I'm trying to run the following query:select distinct on (staff_id) staff_id,

[SQL] select distinct and order by

2004-04-28 Thread Stijn Vanroye
Hello everybody, I have a short question: I'm trying to run the following query: select distinct on (staff_id) staff_id, fullname, loginname from staff where staff_id in (select staff_id from staffmembership where staffgroup_id=#SomeIdValue#) order by fullname I get the follwing error: select

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

[SQL] Select distinct and order by.

2001-07-17 Thread Carlos
Hi all: We have developed an aplication in C with postgresql, using libpq. Our version of development is Postgresql 6.5.3 and it works fine. Now we are migrating the application to various flavours of Linux (S.u.s.e 7.1, tha uses postgresql 7.0.3; Debian Potato, that uses postgresql 7.0.2) and

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

[SQL] SELECT DISTINCT problems

2001-02-28 Thread SCAHILL KEVIN
Hi there, I'm having a lot of trouble with one sql statement and I wonder can you help. I My problem is the following...there are two field name in the the table named LecturerName and Projectcode. Each ProjectCode vulue is unique within the table but there can be many entries in the table with t