Re: a wierd query - Mailing list pgsql-sql

From Achilleus Mantzios
Subject Re: a wierd query
Date
Msg-id Pine.LNX.4.44.0405131033550.21862-100000@matrix.gatewaynet.com
Whole thread Raw
In response to a wierd query  ("ashok@kalculate.com" <ashok@kalculate.com>)
List pgsql-sql
SELECT foo.value from (select string_a as value from main_table UNION 
select string_b as value from main_table) as foo;

O kyrios ashok@kalculate.com egrapse stis May 13, 2004 :

> hi 
> 
> i have a wierd problem and i require an equally weird query.
> 1) backgound
>   Table test:
>     CREATE TABLE main_table (
>                string_A varchar( 20),
>                string_B varchar( 20),
>                );
>      -- both columns are identical in nature and usage
>      INSERT INTO main_table VALUES('abcd','qrst');
>      INSERT INTO main_table VALUES('efgh','efgh');
>      INSERT INTO main_table VALUES('ijkl','abcd');
>      INSERT INTO main_table VALUES('abcd','ijkl');
>      INSERT INTO main_table VALUES('qrst','uvwx');
> 
> 2) problem:
>    
>      i require a query that gives me a result set of the form
> 
>    'abcd'
>    'efgh'
>    'ijkl'
>    'qrst'
>    'uvwx'
> 
>    that is i require the dictinct values from (visualizing each column
> result as a set) the union of the two columns
> 
> 3) questions
> 
>    a) is a query like this possible that can give me the desired result
>    b) if so what would it be.
> 
> 4) remarks
>    
>     i can get the solution using a temporary table and with repeated
>       "insert into temporary select $column from main_table"
> 
> 
> thanks in advance
> 
> ashok
> 
> --------------------------------------------------------------------
> mail2web - Check your email from the web at
> http://mail2web.com/ .
> 
> 
> 
> ---------------------------(end of broadcast)---------------------------
> TIP 6: Have you searched our list archives?
> 
>                http://archives.postgresql.org
> 

-- 
-Achilleus



pgsql-sql by date:

Previous
From: Silke Trißl
Date:
Subject: Re: a wierd query
Next
From: Peter Childs
Date:
Subject: Re: a wierd query