Re: [SQL] Sorting of data from two tables

2011-09-25 Thread David Johnston
On Sep 25, 2011, at 12:37, "R. Smith" wrote: > On Sat, Sep 17, 2011 at 2:56 PM, David Johnston wrote: >> On Sep 17, 2011, at 9:32, "R. Smith" wrote: >> >> >> What I want to do is do a query joining table A with B and sorting >> firstly on a field in Table A then on several fields in Table B. >

Re: [SQL] Sorting of data from two tables

2011-09-25 Thread R. Smith
On Sat, Sep 17, 2011 at 2:56 PM, David Johnston wrote: > On Sep 17, 2011, at 9:32, "R. Smith" wrote: > > > What I want to do is do a query joining table A with B and sorting > firstly on a field in Table A then on several fields in Table B. > > > SELECT a.gdn_gdn, a.gdn_custref, a.gdn_date, a.gdn

Re: [SQL] Sorting of data from two tables

2011-09-17 Thread David Johnston
On Sep 17, 2011, at 9:32, "R. Smith" wrote: > > What I want to do is do a query joining table A with B and sorting > firstly on a field in Table A then on several fields in Table B. > > > SELECT a.gdn_gdn, a.gdn_custref, a.gdn_date, a.gdn_address_name, > a.gdn_method, b.gdn_stockref, b.gdn_row

[SQL] Sorting of data from two tables

2011-09-17 Thread R. Smith
Greetings folks, This is a follow up to my initial message some time ago. Now I have got all the details together. I have two tables. Table A - Which contains one row per entry Table B - Which contains multiple rows per entry Table B relates to Table A by a field say called ID. Table A in this

Re: [SQL] sorting months according to fiscal year

2011-08-22 Thread Gavin Flower
On 23/08/11 01:27, Enzen user wrote: Hi I have to rearrange the months according to the fiscal year i.e from April to march and use the same in the order by clause of a query. I have written the following postgresql function for the same, but to_number is returning an error. Can you please tell

Re: [SQL] sorting months according to fiscal year

2011-08-22 Thread Pavel Stehule
Hello 2011/8/22 Enzen user : > Hi > I have to  rearrange the months according to the fiscal year i.e from April > to march and use the same in the order by clause of a query. > I have written the following postgresql function for the same, but to_number > is returning an error. > Can you please te

[SQL] sorting months according to fiscal year

2011-08-22 Thread Enzen user
Hi I have to rearrange the months according to the fiscal year i.e from April to march and use the same in the order by clause of a query. I have written the following postgresql function for the same, but to_number is returning an error. Can you please tell me where i'm going wrong? Instead of t

Re: [SQL] Sorting Issue

2011-05-25 Thread Ozer, Pam
Of Ozer, Pam Sent: Wednesday, May 18, 2011 3:22 PM To: Tom Lane Cc: Samuel Gendler; em...@encs.concordia.ca; pgsql-sql@postgresql.org Subject: Re: [SQL] Sorting Issue Is there anywhere that gives you all the available collations and their definitions? I found with the C collation it now sorts the

Re: [SQL] Sorting Issue

2011-05-18 Thread Ozer, Pam
: Tuesday, May 10, 2011 9:47 AM To: Ozer, Pam Cc: Samuel Gendler; em...@encs.concordia.ca; pgsql-sql@postgresql.org Subject: Re: [SQL] Sorting Issue "Ozer, Pam" writes: > Isn't this the English standard for collation? Or is this a non-c > locale as mentioned below? Is the

[SQL] Re: [SQL] Sorting data based fields in two linked tables

2011-05-14 Thread Charlie
SELECT A.ID,A.FIELD1,A.FIELD2,  B.FIELD1,B.FIELD2, B.FIELD1,B.FIELD2, B.FIELD1,B.FIELD2 FROM a INNER JOIN B ON a.id = b.a_id ORDER BY a.field2 ASC, b.field1 ASC ; - Reply message - From: "R. Smith" Date: Fri, May 13, 2011 12:00 pm Subject: [SQL] Sorting data based fie

Re: [SQL] Sorting data based fields in two linked tables

2011-05-14 Thread Oliver d'Azevedo Christina
Can you provide An example? Best, Oliveiros Enviado via iPhone Em 13/05/2011, às 04:00 PM, "R. Smith" escreveu: > Hi, > > I am looking for a way to sort data returned from two tables with the > first sort based on a field from table A and the secord sort based on > the results of the first so

[SQL] Sorting data based fields in two linked tables

2011-05-14 Thread R. Smith
Hi, I am looking for a way to sort data returned from two tables with the first sort based on a field from table A and the secord sort based on the results of the first sort but the sort field is from table B. While I can sort on either fields from either table, I cannot get it to work on both. I

Re: [SQL] Sorting Issue

2011-05-10 Thread Scott Marlowe
On Tue, May 10, 2011 at 11:45 AM, Samuel Gendler wrote: > > > On Tue, May 10, 2011 at 9:47 AM, Tom Lane wrote: >> >> "Ozer, Pam" writes: >> > Isn't this the English standard for collation?  Or is this a non-c >> > locale as mentioned below?  Is there anyway around this? >> >> >        LC_COLLATE

Re: [SQL] Sorting Issue

2011-05-10 Thread Samuel Gendler
On Tue, May 10, 2011 at 9:47 AM, Tom Lane wrote: > "Ozer, Pam" writes: > > Isn't this the English standard for collation? Or is this a non-c > > locale as mentioned below? Is there anyway around this? > > >LC_COLLATE = 'en_US.utf8' > > en_US is probably using somebody's idea of "dictio

Re: [SQL] Sorting Issue

2011-05-10 Thread Edward W. Rouse
: pgsql-sql@postgresql.org Subject: Re: [SQL] Sorting Issue That works. Why? -Original Message- From: Emi Lu [mailto:em...@encs.concordia.ca] Sent: Monday, May 09, 2011 12:38 PM To: Ozer, Pam Cc: pgsql-sql@postgresql.org Subject: Re: [SQL] Sorting Issue > I have the following query > &g

Re: [SQL] Sorting Issue

2011-05-10 Thread Tom Lane
"Ozer, Pam" writes: > Isn't this the English standard for collation? Or is this a non-c > locale as mentioned below? Is there anyway around this? >LC_COLLATE = 'en_US.utf8' en_US is probably using somebody's idea of "dictionary order", which I believe includes ignoring spaces

Re: [SQL] Sorting Issue

2011-05-10 Thread Ozer, Pam
7;; Samuel Gendler Cc: em...@encs.concordia.ca; pgsql-sql@postgresql.org Subject: RE: [SQL] Sorting Issue The collate setting is LC_COLLATE = 'English_United States.1252' -Original Message- From: Tom Lane [mailto:t...@sss.pgh.pa.us] Sent: Monday, May 09, 201

Re: [SQL] Sorting Issue

2011-05-10 Thread Ozer, Pam
I was wrong it is LC_COLLATE = 'en_US.utf8' -Original Message- From: Ozer, Pam Sent: Monday, May 09, 2011 3:13 PM To: 'Tom Lane'; Samuel Gendler Cc: em...@encs.concordia.ca; pgsql-sql@postgresql.org Subject: RE: [SQL] Sorting Issue Th

Re: [SQL] Sorting Issue

2011-05-09 Thread Ozer, Pam
The collate setting is LC_COLLATE = 'English_United States.1252' -Original Message- From: Tom Lane [mailto:t...@sss.pgh.pa.us] Sent: Monday, May 09, 2011 2:29 PM To: Samuel Gendler Cc: em...@encs.concordia.ca; Ozer, Pam; pgsql-sql@postgresql.org Subject: Re: [SQL] Sor

Re: [SQL] Sorting Issue

2011-05-09 Thread Tom Lane
Samuel Gendler writes: > It's not at all clear why they are not coming out of the db in > alphabetically sorted order when the query includes "order by > VehicleTrimAbbreviated asc" Usually the thing to ask at this point is "what's the database's LC_COLLATE setting"? Non-C locales often have tr

Re: [SQL] Sorting Issue

2011-05-09 Thread Samuel Gendler
On Mon, May 9, 2011 at 1:38 PM, Emi Lu wrote: > Hi Pam, > > > >> Select VehicleTrimAbbreviated, VehicleTrimAbbreviatedId > >> from VehicleTrimAbbreviated > >> Where vehicleTrimAbbreviated like 'CX%' > >> order by > >> > >> split_part(VehicleTrimAbbreviated, ' ', 1) asc, > >> split_part(VehicleTri

Re: [SQL] Sorting Issue

2011-05-09 Thread Emi Lu
:em...@encs.concordia.ca] Sent: Monday, May 09, 2011 12:52 PM To: Ozer, Pam Cc: pgsql-sql@postgresql.org Subject: Re: [SQL] Sorting Issue That works. Why? http://www.postgresql.org/docs/current/static/functions-string.html split_part(string text, delimiter text, field int) textSpli

Re: [SQL] Sorting Issue

2011-05-09 Thread Ozer, Pam
Ok but why doesn't the other way work? I can't use the function in my query. It is dynamically created. -Original Message- From: Emi Lu [mailto:em...@encs.concordia.ca] Sent: Monday, May 09, 2011 12:52 PM To: Ozer, Pam Cc: pgsql-sql@postgresql.org Subject: Re: [SQL] Sor

Re: [SQL] Sorting Issue

2011-05-09 Thread Emi Lu
Original Message- From: Emi Lu [mailto:em...@encs.concordia.ca] Sent: Monday, May 09, 2011 12:38 PM To: Ozer, Pam Cc: pgsql-sql@postgresql.org Subject: Re: [SQL] Sorting Issue I have the following query Select VehicleTrimAbbreviated, VehicleTrimAbbreviatedId from VehicleTr

Re: [SQL] Sorting Issue

2011-05-09 Thread Ozer, Pam
That works. Why? -Original Message- From: Emi Lu [mailto:em...@encs.concordia.ca] Sent: Monday, May 09, 2011 12:38 PM To: Ozer, Pam Cc: pgsql-sql@postgresql.org Subject: Re: [SQL] Sorting Issue > I have the following query > > Select VehicleTrimAbbreviated, VehicleTrimAbbr

Re: [SQL] Sorting Issue

2011-05-09 Thread Emi Lu
I have the following query Select VehicleTrimAbbreviated, VehicleTrimAbbreviatedId from VehicleTrimAbbreviated Where vehicleTrimAbbreviated like 'CX%' order by VehicleTrimAbbreviated asc Results: 532;"CX Hatchback" 536;"CXL Minivan" 3255;"CXL Premium Sedan" 537;"CXL Sedan" 538;"CXL Sport

[SQL] Sorting Issue

2011-05-09 Thread Ozer, Pam
I have the following query Select VehicleTrimAbbreviated, VehicleTrimAbbreviatedId from VehicleTrimAbbreviated Where vehicleTrimAbbreviated like 'CX%' order by VehicleTrimAbbreviated asc Results: 532;"CX Hatchback" 536;"CXL Minivan" 3255;"CXL Premium Sedan" 537;"CXL Sedan" 538;"CXL

Re: [SQL] Sorting router interfaces

2010-11-01 Thread Andreas
Am 01.11.2010 13:15, schrieb Brian Sherwood: I am trying to sort router interface names. The problem is that I am doing a text sort and need to do a numerical sort. What I get instead is the following text ordering: GigabitEthernet1/0/1| 1/0/1 | {1,0,1} GigabitEthernet1/0/10 | 1/

Re: [SQL] Sorting router interfaces

2010-11-01 Thread Filip Rembiałkowski
2010/11/1 Brian Sherwood : > I am trying to sort router interface names. > The problem is that I am doing a text sort and need to do a numerical sort. > > I want the interfaces to be in numerical order: > >  GigabitEthernet1/0/1    | 1/0/1 | {1,0,1} >  GigabitEthernet1/0/2    | 1/0/2 | {1,0

[SQL] Sorting router interfaces

2010-11-01 Thread Brian Sherwood
I am trying to sort router interface names. The problem is that I am doing a text sort and need to do a numerical sort. I want the interfaces to be in numerical order:  GigabitEthernet1/0/1    | 1/0/1 | {1,0,1}  GigabitEthernet1/0/2    | 1/0/2 | {1,0,2}  GigabitEthernet1/0/3    | 1/0/3   

Re: [SQL] Sorting items in aggregate function (thanks)

2006-09-15 Thread Steven Murdoch
On Tue, Sep 12, 2006 at 04:37:55PM -0400, Tom Lane wrote: > Note that if you need to GROUP in the outer query, it's best to sort the > inner query's output first by the outer query's grouping: ... Great - this works fine. Thanks also to the other people who replied. Steven. -- w: http://www.cl.

Re: [SQL] Sorting items in aggregate function

2006-09-12 Thread Osvaldo Rosario Kussama
Steven Murdoch escreveu: I would like to concatenate sorted strings in an aggregate function. I found a way to do it without sorting[1], but not with. Here is an example of a setup and what I could like to achieve. Does anyone have suggestions on what is the best way to get the desired result?

Re: [SQL] Sorting items in aggregate function

2006-09-12 Thread Tom Lane
Michael Fuhr <[EMAIL PROTECTED]> writes: > On Tue, Sep 12, 2006 at 04:46:28PM +0100, Steven Murdoch wrote: >> Here is an example of a setup and what I could like to achieve. Does >> anyone have suggestions on what is the best way to get the desired >> result? > Use the aggregate over an ordered su

Re: [SQL] Sorting items in aggregate function

2006-09-12 Thread Volkan YAZICI
On Sep 12 04:46, Steven Murdoch wrote: > I would like to concatenate sorted strings in an aggregate function. I > found a way to do it without sorting[1], but not with. If the array elements will be made of integers, then you can use sort() procedure comes with intarray contrib module. For instanc

Re: [SQL] Sorting items in aggregate function

2006-09-12 Thread Michael Fuhr
On Tue, Sep 12, 2006 at 04:46:28PM +0100, Steven Murdoch wrote: > Here is an example of a setup and what I could like to achieve. Does > anyone have suggestions on what is the best way to get the desired > result? Use the aggregate over an ordered subquery: SELECT name, trim(concat(code || ' '))

[SQL] Sorting items in aggregate function

2006-09-12 Thread Steven Murdoch
I would like to concatenate sorted strings in an aggregate function. I found a way to do it without sorting[1], but not with. Here is an example of a setup and what I could like to achieve. Does anyone have suggestions on what is the best way to get the desired result? Thanks, Steven. CREATE TAB

Re: [SQL] Sorting aggregate column contents

2006-05-03 Thread Everton Luís Berz
People from brazilian postgresql list sent me another way to sort the column contents. The way is the aggregate accumulate values and after run an array sort function. It worked fine. I think the subquery in function f_select_array does not decrease performance. Follow the code: --from http://arc

Re: [SQL] Sorting aggregate column contents

2006-05-03 Thread Everton Luís Berz
Thanks a lot the explanation. I tested all cases and I noticed that reordering the source table (city) not works on all cases, so I think Postgresql perform different internal sort to optimize some query's. I noticed this in other query I performed: select s.ano, s.semestre,

Re: [SQL] Sorting aggregate column contents

2006-05-02 Thread Ben K.
It works fine. But I wouldn't like using subselect's, then if somebody else knows about an operator or something like that to put on the aggregator, please tell me. I think the nature of the f_concat makes it difficult to sort, since it simply adds the next value, so if the source table gives

Re: [SQL] Sorting aggregate column contents

2006-05-02 Thread Everton Luís Berz
It works fine. But I wouldn't like using subselect's, then if somebody else knows about an operator or something like that to put on the aggregator, please tell me. Volkan YAZICI escreveu: On May 02 06:00, Everton Luís Berz wrote: Is it possible to sort the content of an aggregate text co

Re: [SQL] Sorting aggregate column contents

2006-05-02 Thread Bruno Wolff III
On Wed, May 03, 2006 at 00:13:40 +0300, Volkan YAZICI <[EMAIL PROTECTED]> wrote: > On May 02 06:00, Everton Luís Berz wrote: > > Is it possible to sort the content of an aggregate text column? > > > > Query: > > select s.name, ag_concat(c.name) from state s > > inner join city c on (c.idstate =

Re: [SQL] Sorting aggregate column contents

2006-05-02 Thread Volkan YAZICI
On May 02 06:00, Everton Luís Berz wrote: > Is it possible to sort the content of an aggregate text column? > > Query: > select s.name, ag_concat(c.name) from state s > inner join city c on (c.idstate = s.idstate) > group by s.name > order by s.name; IMHO, you can receive results ordered by using

[SQL] Sorting aggregate column contents

2006-05-02 Thread Everton Luís Berz
Is it possible to sort the content of an aggregate text column? Query: select s.name, ag_concat(c.name) from state s inner join city c on (c.idstate = s.idstate) group by s.name order by s.name; Result: name | ag_concat ---+--- RS| Porto Alegre, Gramado SP

Re: [SQL] sorting by day of the week

2006-01-24 Thread ipv
ssage - From: "Joseph Shraibman" To: Sent: Wednesday, January 25, 2006 2:23 AM Subject: [SQL] sorting by day of the week p8:owl=>SELECT to_char( logtime, 'Dy'),count(*) FROM logtab WHERE date_trunc('day', logtime) > current_date + '7 day ago&

Re: [SQL] sorting by day of the week

2006-01-24 Thread Joseph Shraibman
Nevermind, I figured out that I just needed to do it like this: SELECT to_char( logtime, 'Dy'),count(*),to_char( logtime, 'D') FROM sclog WHERE date_trunc('day', logtime) > current_date + '7 day ago'::interval group by to_char( logtime, 'Dy'),to_char( logtime, 'D') ORDER BY to_char( logtime, '

[SQL] sorting by day of the week

2006-01-24 Thread Joseph Shraibman
p8:owl=>SELECT to_char( logtime, 'Dy'),count(*) FROM logtab WHERE date_trunc('day', logtime) > current_date + '7 day ago'::interval group by to_char( logtime, 'Dy') ORDER BY to_char( logtime, 'Dy') DESC; to_char | count -+--- Wed | 1447 Tue | 618 Thu | 1161 Sun

Re: [SQL] Sorting problem

2004-07-16 Thread Stu
Pop text in front of that first value and it works: template1=# select text '##107990' template1=# as "sortfield" template1-# union template1-# select '###17990' template1-# order by sortfield; sortfield ---

Re: [SQL] Sorting problem

2004-07-16 Thread Stephan Szabo
On Mon, 12 Jul 2004, Ruggero wrote: > Hi all, > I have a problem sorting varchar fields. > I will explain the problem with a simple example: > > this query >select '##10' as sortfield >union >select '###1' as sortfield >order by sortfield > produces this correct output: >'###1'

[SQL] Sorting problem

2004-07-16 Thread Ruggero
Hi all, I have a problem sorting varchar fields. I will explain the problem with a simple example: this query select '##10' as sortfield union select '###1' as sortfield order by sortfield produces this correct output: '###1' '##10' but this one select '##10--

Re: [SQL] Sorting an aggregated column

2004-03-23 Thread Tom Lane
"David Witham" <[EMAIL PROTECTED]> writes: > So I see that there is the extra sort above the sub-query that > wouldn't be there using 7.4. Are you saying that the sort by survey > after the sort by survey,question would potentially reorder the > records initially sorted by survey,question? Exactly

Re: [SQL] Sorting an aggregated column

2004-03-22 Thread David Witham
ese rows even though they don't need to be? Regards, David -Original Message- From: Tom Lane [mailto:[EMAIL PROTECTED] Sent: Tuesday, 23 March 2004 16:17 To: David Witham Cc: [EMAIL PROTECTED] Subject: Re: [SQL] Sorting an aggregated column "David Witham" <[EMAIL PROTECTED]

Re: [SQL] Sorting an aggregated column

2004-03-22 Thread Tom Lane
"David Witham" <[EMAIL PROTECTED]> writes: > This output is correct in this case but there is no guarantee that the > answers will come out in "question" order. I can't see how to > incorporate sorting by the "question" column using this approach. As of PG 7.4 you can reliably use a sorted sub-sel

[SQL] Sorting an aggregated column

2004-03-22 Thread David Witham
Hi all, I ran these commands: create temp table dw_survey(survey int,question int,answer_bool boolean,answer_int int,answer_char varchar); insert into dw_survey values(1,1,'t',null,null); insert into dw_survey values(1,2,'f',null,null); insert into dw_survey values(1,3,'t',null,null); insert int

Re: [SQL] Sorting problem

2003-10-16 Thread R. van Twisk
I think what you actually want is natural sorting. Ries > -Oorspronkelijk bericht- > Van: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] Jean-Luc Lachance > Verzonden: woensdag 15 oktober 2003 17:43 > Aan: George A.J > CC: [EMAIL PROTECTED] > Onderwerp: Re:

Re: [SQL] Sorting problem

2003-10-15 Thread Jean-Luc Lachance
You are obviously not using C locale. If you can't change it for some reason, you can use: select * from accounts order by int4( trim( acno, '#')); JLL "George A.J" wrote: > > hi all, > i am using postgres 7.3.2 .i am converitng a mssql database to > postgres. > now i am facing a strange proble

Re: [SQL] Sorting problem

2003-10-14 Thread Stephan Szabo
On Tue, 14 Oct 2003, George A.J wrote: > hi all, > i am using postgres 7.3.2 .i am converitng a mssql database to postgres. > now i am facing a strange problem. sorting based on a varchar field is not working > as expected. the non alphanumeric characters are not sorting based on the ascii > valu

[SQL] Sorting problem

2003-10-14 Thread George A.J
hi all, i am using postgres 7.3.2 .i am converitng a mssql database to postgres. now i am facing a strange problem. sorting based on a varchar field is not working as expected. the non alphanumeric characters are not sorting based on the ascii value of them.   i have the following table structure.

[SQL] sorting

2003-09-13 Thread chester c young
how do you set sorting for indicies and order by? is it set once for the database, or can it be set per index? __ Do you Yahoo!? Yahoo! SiteBuilder - Free, easy-to-use web site design software http://sitebuilder.yahoo.com ---(end of broadc

Re: [SQL] Sorting by NULL values

2003-03-05 Thread Rod Taylor
On Tue, 2003-03-04 at 15:13, Stephan Szabo wrote: > On Tue, 4 Mar 2003, Ian Burrell wrote: > > > I am doing a query where I need to sort by a column that may be NULL > > because it is coming from an OUTER JOIN. I noticed a difference between > > PostgreSQL and other databases about where NULLs sh

Re: [SQL] Sorting and then...

2001-04-10 Thread Jason Earl
SELECT name FROM test ORDER BY id DESC LIMIT 10; Take care, Jason --- Wei Weng <[EMAIL PROTECTED]> wrote: > Suppose I have a table > > create table test > ( > id integer, > name text > ); > > And I want to get the names of the largest 10 "id"s. > How can I do that in > sql?

RE: [SQL] Sorting and then...

2001-04-10 Thread Michael Ansley
Title: RE: [SQL] Sorting and then... But if you want the largest 10, then you can: SELECT name FROM ORDER BY id DESC LIMIT 10; assuming that you mean largest numerically. Cheers... MikeA >> -Original Message- >> From: Roberto Mello [mailto:[EMAIL PROTECTED]]

Re: [SQL] Sorting and then...

2001-04-09 Thread Roberto Mello
On Mon, Apr 09, 2001 at 07:22:52PM -0400, Wei Weng wrote: > And I want to get the names of the largest 10 "id"s. How can I do that in > sql? What do you mean by "largest"? Largest id? "largest" text string? If it's the id you can do: select max(id) from ; -Roberto --

[SQL] Sorting and then...

2001-04-09 Thread Wei Weng
Suppose I have a table create table test ( id integer, name text ); And I want to get the names of the largest 10 "id"s. How can I do that in sql? Thanks! ---(end of broadcast)--- TIP 2: you can get off all lists at once with t

[SQL] sorting the text values as integers

2000-12-20 Thread Sandis Jerics
Hi, i have a table with some text fields filled with a data like 100,23 235,12 500 200 the same fields somethimes contains the values like 100x100x25 125x125x50 200x80x90 and so on. the client requires that rows are sorted in ascending order for the case there are a float values, i

[SQL] sorting in UNICODE table

2000-08-24 Thread Alex Guryanow
Hi, I'm use postgresql-7.0.2. It's compiled with unicode support (./configure --enable-multibyte=UNICODE ...) I have a table which contains both latin and non-latin letters. All they are in UTF-8 encoding. When I try to sort the rows ( SELECT * FROM my_table ORDER BY sort_field ) I receive str