You are here: Re: Mix two tables in a single SELECT statement - not a join « PHP Programming Language « IT news, forums, messages
Re: Mix two tables in a single SELECT statement - not a join

Posted by Tim Roberts on 11/11/05 06:54

"bizt" <bissatch@yahoo.co.uk> wrote:

>Ok, tried a simple example:
>
>$select = "SELECT title, desctext FROM commnews UNION SELECT title,
>article AS desctext FROM pressnews ORDER BY createdon";
>
>$result = pg_exec ($db, $select);
>
>But giving me the following error:
>
>Warning: pg_exec(): Query failed: ERROR: column "createdon" does not
>exist in /data/httpd/VirtualHosts/web-sandbox/htdocs/_testing/union.php
>on line 34
>
>The column 'createdon' does exist in both so I can only assume that my
>ORDER BY command isnt properly formated. Is this the correct way to
>ORDER a UNION SELECT?

Almost. The union-ed query does not have column names, so you have to
refer to them by number. That means the column must participate in the
query. This should work:

SELECT title, desctext, createdon FROM commnews
UNION
SELECT title, article, createdon FROM pressnews
ORDER BY 3;
--
- Tim Roberts, timr@probo.com
Providenza & Boekelheide, Inc.

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация