Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id 5916FB5DBCE for ; Sun, 25 Sep 2011 15:45:01 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.29]) (amavisd-maia, port 10024) with ESMTP id 96381-01 for ; Sun, 25 Sep 2011 18:44:54 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.8.0-rc2 Received: from nm21.bullet.mail.ac4.yahoo.com (nm21.bullet.mail.ac4.yahoo.com [98.139.52.218]) by mail.postgresql.org (Postfix) with SMTP id 183E3B5DBCA for ; Sun, 25 Sep 2011 15:44:53 -0300 (ADT) Received: from [98.139.52.192] by nm21.bullet.mail.ac4.yahoo.com with NNFMP; 25 Sep 2011 18:44:53 -0000 Received: from [98.139.52.168] by tm5.bullet.mail.ac4.yahoo.com with NNFMP; 25 Sep 2011 18:44:53 -0000 Received: from [127.0.0.1] by omp1051.mail.ac4.yahoo.com with NNFMP; 25 Sep 2011 18:44:53 -0000 X-Yahoo-Newman-Id: 289238.29895.bm@omp1051.mail.ac4.yahoo.com Received: (qmail 36180 invoked from network); 25 Sep 2011 18:44:53 -0000 DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com; h=DKIM-Signature:X-Yahoo-Newman-Property:X-YMail-OSG:X-Yahoo-SMTP:Received:References:Mime-Version:In-Reply-To:X-Apple-Yahoo-Original-Message-Folder:Content-Type:Content-Transfer-Encoding:Message-Id:Cc:X-Mailer:From:X-Apple-Yahoo-Replied-Msgid:Subject:Date:To; b=rWSRdyqmsAuJgJVM68b6khjyg8995h6QEYRXoT/jpg87SBXNiP2XNuknFZwwo4Qhx3BihvewDeQjttjKbDMDFxElH56utEIlfcfE8cafDiPJoYkUQktssxiv5VqLh6yp59wxR7WOpTx90ImoHonadNGSILUD6q+RhRJ1T6FZ1ak= ; DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s1024; t=1316976293; bh=4y3TEeZUrWrhSBxrB+TTnF57a20mFeMhcW8YA145yF4=; h=X-Yahoo-Newman-Property:X-YMail-OSG:X-Yahoo-SMTP:Received:References:Mime-Version:In-Reply-To:X-Apple-Yahoo-Original-Message-Folder:Content-Type:Content-Transfer-Encoding:Message-Id:Cc:X-Mailer:From:X-Apple-Yahoo-Replied-Msgid:Subject:Date:To; b=qTgZUYGnG9Mulx3YHxtX8FNWhEcuY2YNDY9LEitRx1EnZXx7rP7dGaqslRN825Aeaz+6yvV6rBfzR+PgxeZ5ID8HZpXvbT4d77jtx8Qc1mY0rSAoJgIMbiLp4zYzlHgpdK4WfZuHf/LcTK8laVvEsSVO9GvwRxNa/oevT5Up+Hc= X-Yahoo-Newman-Property: ymail-3 X-YMail-OSG: IrKTSRcVM1lCBVPOqZ2e2_qPtqnByM3K5nyRLp0eu2KrS73 kUI57xxDfmye1o08XBq4mVHh7_CZaQ3DuGg9QvVOjhQKgdpyFiRLUfiPfWTo kTKij3ccePh6NW0805YgWFrIt_Ll_.qztTCmgqr4Vn4WbVs7p__CSAmfzq6q 5pPVEaFHWlPKjdQkFrcED3eO37P4qJSQ7mMEjsaIA5W8rF3XDBpYXqJIiap3 5qx_HdzPpk5KUQBWa.xSq4O0cZ24kSkHL8TWW3nGwihBlfgSEUoloLcsZKvy OuU2Fc0Nf6GS5JTtNuZabaM.aO6UYExb0SeeOGx5ZmEiDg8cHA74EuYSmZD7 iKp23SGr8gPrSaFJHcsjvSN9Kwuho8WwCWADQNHS0kpHUk50KHeIa6P6OkGK kXNsYcA-- X-Yahoo-SMTP: mpGJl6eswBD2IBufoVEg0Pa8gg-- Received: from [192.12.17.102] (polobo@24.93.23.188 with xymcookie) by smtp113-mob.biz.mail.ac4.yahoo.com with SMTP; 25 Sep 2011 11:44:53 -0700 PDT References: <27CF61B6-2101-4FD7-91BD-DC82C59E9015@yahoo.com> Mime-Version: 1.0 (iPad Mail 8J2) In-Reply-To: X-Apple-Yahoo-Original-Message-Folder: Inbox Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable Message-Id: <0979B205-58B1-4C58-BED6-FED40C4665A2@yahoo.com> Cc: "pgsql-sql@postgresql.org" X-Mailer: iPad Mail (8J2) From: David Johnston X-Apple-Yahoo-Replied-Msgid: 1_85800_AOekiGIAAQcOTn9aJgy0iGkwvqk Subject: Re: Sorting of data from two tables Date: Sun, 25 Sep 2011 14:44:52 -0400 To: "R. Smith" X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-2.403 tagged_above=-5 required=5 tests=BAYES_00=-1.9, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RP_MATCHES_RCVD=-0.504 X-Spam-Level: X-Archive-Number: 201109/78 X-Sequence-Number: 35878 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: >>=20 >>=20 >> 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. >>=20 >>=20 >> SELECT a.gdn_gdn, a.gdn_custref, a.gdn_date, a.gdn_address_name, >> a.gdn_method, b.gdn_stockref, b.gdn_row, b.gdn_bay, b.gdn_shelf >> FROM a >> LEFT JOIN b >> ON a.gdn_gdn =3D b.gdn_gdn >> ORDER BY a.gdn_method,b.gdn_row, b.gdn_bay, b.gdn_shelf >>=20 >>=20 >> It would help if you gave an example comparing the above query results wi= th >> your desired results. It would also help if you actually provided a >> detailed description of you goal instead of the generic one quoted above.= >> Given your stated need the query does exactly what you requested. >> David J. >=20 > Ok, here is some more specific information. The data stored is > inventory pick data. > We have a table which stores all the header information, addresses etc > (Table A) and > then each order line (Table B) which stores item to be picked and location= . >=20 >=20 There isn't any useable way to output a variable number of columns. So, you= need to decide how the data is going to be used and specify the order by ac= cordingly. You can use window functions to capture some of the order informa= tion from discontiguous lines; including ARRAY_AGG(). You should also ask yourself if you are trying to do too much with a single q= uery/report. If you are stuck with CSV export your non-SQL options are limi= ted but maybe your reporting environment can assist. If you are stuck with C= SV you could try using array_agg and then convert the resultant array to a f= ormatted string for output. CSV would surround the entire formatted output i= n quotes but maybe you could post-process the result to remove the quotes so= that, say Excel, would see the string as simply being additional columns in= the file. David J.=