Received: from makus.postgresql.org (makus.postgresql.org [98.129.198.125]) by mail.postgresql.org (Postfix) with ESMTP id 8B36316E34F7 for ; Sat, 17 Dec 2011 05:03:01 -0400 (AST) Received: from mailout01.ims-firmen.de ([213.174.32.96]) by makus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1RbqAX-0000wg-4L for pgsql-sql@postgresql.org; Sat, 17 Dec 2011 09:03:02 +0000 Received: from mailin01.ims-firmen.de ([192.168.1.110]) by mailout01.ims-firmen.de with esmtp (envelope-from ) id 1RbqAJ-0000zS-BB for pgsql-sql@postgresql.org; Sat, 17 Dec 2011 10:02:47 +0100 Received: from [87.170.176.71] (helo=a-kretschmer.de) by mailin01.ims-firmen.de with esmtpsa (TLSv1:AES256-SHA:256) (envelope-from ) id 1RbqAJ-0007rL-60 for pgsql-sql@postgresql.org; Sat, 17 Dec 2011 10:02:47 +0100 Received: from kretschmer by a-kretschmer.de with local (Exim 4.69) (envelope-from ) id 1RbqAI-0003LM-4l for pgsql-sql@postgresql.org; Sat, 17 Dec 2011 10:02:46 +0100 Date: Sat, 17 Dec 2011 10:02:46 +0100 From: Andreas Kretschmer To: pgsql-sql@postgresql.org Subject: Re: Column "..." does not exist (view + union) Message-ID: <20111217090246.GA12209@tux> References: <4EEC0533.9050007@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <4EEC0533.9050007@gmail.com> X-OS: Debian/GNU Linux - weil ich es mir Wert bin! X-GPG-Fingerprint: EE16 3C01 7B9C 10F7 2C8B 3B86 4DB3 D9EE 7F45 84DA X-Message-Flag: "Windows" is not the answer. "Windows" is the question and the answer is "no"! X-Lugdd: Gerd Kube X-Info: My name is root. Just root. And I am licensed to kill -9 User-Agent: Mutt/1.5.18 (2008-05-17) X-Pg-Spam-Score: 0.3 (/) X-Archive-Number: 201112/64 X-Sequence-Number: 36125 Stefan Weiss wrote: > > - running this query - > > 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". Rewrite your query to something like: select name from (select name, ctype from ... union select name, ctype from ...) foo order by ctype Andreas -- Really, I'm not out to destroy Microsoft. That will just be a completely unintentional side effect. (Linus Torvalds) "If I was god, I would recompile penguin with --enable-fly." (unknown) Kaufbach, Saxony, Germany, Europe. N 51.05082°, E 13.56889°