Received: from makus.postgresql.org (makus.postgresql.org [98.129.198.125]) by mail.postgresql.org (Postfix) with ESMTP id 20F5E16E34F9 for ; Sat, 17 Dec 2011 10:28:30 -0400 (AST) Received: from fep14.mx.upcmail.net ([62.179.121.34]) by makus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1RbvFU-0005jB-QK for pgsql-sql@postgresql.org; Sat, 17 Dec 2011 14:28:29 +0000 Received: from edge03.upcmail.net ([192.168.13.238]) by viefep14-int.chello.at (InterMail vM.8.01.05.04 201-2260-151-105-20111014) with ESMTP id <20111217142814.QAWN12772.viefep14-int.chello.at@edge03.upcmail.net> for ; Sat, 17 Dec 2011 15:28:14 +0100 Received: from [192.168.11.128] ([213.47.132.228]) by edge03.upcmail.net with edge id AEUE1i00Z4vpPQ503EUEQM; Sat, 17 Dec 2011 15:28:14 +0100 X-SourceIP: 213.47.132.228 Message-ID: <4EECA699.2020700@gmail.com> Date: Sat, 17 Dec 2011 15:26:33 +0100 From: Stefan Weiss User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.23) Gecko/20110922 Thunderbird/3.1.15 MIME-Version: 1.0 To: pgsql-sql@postgresql.org Subject: Re: Column "..." does not exist (view + union) References: <4EEC0533.9050007@gmail.com> <20111217090246.GA12209@tux> In-Reply-To: <20111217090246.GA12209@tux> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -1.1 (-) X-Archive-Number: 201112/66 X-Sequence-Number: 36127 On 2011-12-17 10:02, Andreas Kretschmer wrote: > Stefan Weiss wrote: >> >> SELECT name >> FROM dossier_contact_v >> WHERE dossier_id = 56993 >> AND ctype = 234 >> UNION >> SELECT name >> FROM dossier_contact_v >> WHERE dossier_id = -1 >> AND ctype = -1 >> ORDER BY ctype; >> >> - fails with the following error message: >> >> ERROR: column "ctype" does not exist >> LINE 10: ORDER BY ctype; > > The reult table doesn't contain a column "ctype", it contains only > "name". [...] I see. So this has to do with the union; after combining the two queries, the tables from the FROM clauses are no longer available. Thanks, that explains it. - stefan