Skip site navigation (1) Skip section navigation (2)

Re: a wierd query

From: Silke Trißl <trissl(at)informatik(dot)hu-berlin(dot)de>
To: ashok(at)kalculate(dot)com, SQL PostgreSQL <pgsql-sql(at)postgresql(dot)org>
Subject: Re: a wierd query
Date: 2004-05-13 08:41:10
Message-ID: 40A334A6.5010400@informatik.hu-berlin.de (view raw or flat)
Thread:
Lists: pgsql-sql

ashok(at)kalculate(dot)com schrieb:

>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.
>

Yes, the follwoing
 select t1.string_a from main_table t1
union
select t2.string_b from main_table t2;

>
>4) remarks
>   
>    i can get the solution using a temporary table and with repeated
>      "insert into temporary select $column from main_table"
>  
>
Why, SQL does the trick!


>
>thanks in advance
>
>ashok
>
>  
>

Silke

>  
>



In response to

pgsql-sql by date

Next:From: Peter ChildsDate: 2004-05-13 09:17:46
Subject: Re: a wierd query
Previous:From: ashok@kalculate.comDate: 2004-05-13 08:07:08
Subject: a wierd query

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group