Re: How to join tables with different columns and different number of rows?

From: Martijn van Oosterhout <kleptog(at)svana(dot)org>
To: Igor <dbmanager(at)osb368(dot)nnov(dot)ru>
Cc: Richard Huxton <dev(at)archonet(dot)com>, pgsql-general(at)postgresql(dot)org
Subject: Re: How to join tables with different columns and different number of rows?
Date: 2001-06-27 10:45:20
Message-ID: 20010627204520.B11365@svana.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Wed, Jun 27, 2001 at 02:25:23PM +0400, Igor wrote:
> Thank you for replay, it is working, but
> i would like to get result table with 5 rows.
> In your example we willl get 8 rows

I think it's time to reexamine what you're trying to acheive. What you are
asking is not possible with SQL, at least not easily. Do it in your client
code.

> RH> From: "Igor" <dbmanager(at)osb368(dot)nnov(dot)ru>
>
> >> Hello!
> >>
> >> What SQL query will help me to concatenate two different tables
> >> with different number of rows? For example , i have first table
> >> with column1 and column2 , having 3 rows , and second table
> >> with column3, column4 , having 5 rows. How to make
> >> third table with column1,column2,column3,column4 and 5 rows in it
> >> (and last two rows in column1 and column2 are empty)
>
> RH> Something along the lines of:
>
> RH> SELECT col1,col2,'' as dummy3, '' as dummy4
> RH> FROM table1
> RH> UNION
> RH> SELECT '' as dummy1, '' as dummy2, col3, col4
> RH> FROM table2

--
Martijn van Oosterhout <kleptog(at)svana(dot)org>
http://svana.org/kleptog/
- Artificial Intelligence is the science of making computers that behave
- like the ones in the movies.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Richard Church 2001-06-27 11:12:03 Re: Blobs in PostgreSQL
Previous Message Igor 2001-06-27 10:25:23 Re[2]: How to join tables with different columns and different number of rows?