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

Поиск
Список
Период
Сортировка
От Richard Huxton
Тема Re: How to join tables with different columns and different number of rows?
Дата
Msg-id 002d01c0feed$a3bab380$1001a8c0@archonet.com
обсуждение исходный текст
Ответ на Complicated query... is there a simpler way?  (Joshua Adam Ginsberg <rainman@owlnet.rice.edu>)
Ответы Re[2]: How to join tables with different columns and different number of rows?  (Igor <dbmanager@osb368.nnov.ru>)
Список pgsql-general
From: "Igor" <dbmanager@osb368.nnov.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)

Something along the lines of:

SELECT col1,col2,'' as dummy3, '' as dummy4
FROM table1
UNION
SELECT '' as dummy1, '' as dummy2, col3, col4
FROM table2

should do it for you (not tested)

- Richard Huxton


В списке pgsql-general по дате отправления:

Предыдущее
От: Igor
Дата:
Сообщение: How to join tables with different columns and different number of rows?
Следующее
От: Thierry Besancon
Дата:
Сообщение: Re: PostgreSQL book online