Re: How to append tables in a view - Mailing list pgsql-general

From Shane Ambler
Subject Re: How to append tables in a view
Date
Msg-id 45D183C5.2040408@007Marketing.com
Whole thread Raw
In response to How to append tables in a view  ("Ashish Karalkar" <ashish.karalkar@info-spectrum.com>)
Responses Re: How to append tables in a view  ("Shoaib Mir" <shoaibmir@gmail.com>)
List pgsql-general
Ashish Karalkar wrote:
> Hello List,
>
> I want to append column of two different tables in a single column of  a view .
>
> data type of tow column of two diffrent tables will be same.
>
> WHAT I WANT TO DO IS:
>
>       Table 1
>       ID DESC
>       1 A
>       2 B
>       3 C
>
>
>
>
>
>       Table 2
>       ID DESC
>       1 D
>       2 E
>       3 F
>
>
>
>       View(Table1|| Table 2)
>       ID_view Desc
>
>       1 A
>       2 B
>       3 C
>       4 D
>       5 E
>       6 F
>
>
>
> Is there any way???

A union -

SELECT id,desc FROM table1
UNION
SELECT id,desc FROM table2;

This will give you

ID_view Desc

1 A
2 B
3 C
1 D
2 E
3 F


If you actually want the id_view column to show 1 through 6 then you
will want to generate a sequence that is shown for that column instead
of the original id column. Or generate the id_view in the client, such
as use the row position in the returned set.




--

Shane Ambler
pgSQL@007Marketing.com

Get Sheeky @ http://Sheeky.Biz

pgsql-general by date:

Previous
From: Alban Hertroys
Date:
Subject: Re: How to append tables in a view
Next
From: "Shoaib Mir"
Date:
Subject: Re: How to append tables in a view