Re: join two tables without a key

Поиск
Список
Период
Сортировка
От Raymond O'Donnell
Тема Re: join two tables without a key
Дата
Msg-id 4BB72973.8090706@iol.ie
обсуждение исходный текст
Ответ на Re: join two tables without a key  (Dino Vliet <dino_vliet@yahoo.com>)
Список pgsql-general
On 03/04/2010 12:32, Dino Vliet wrote:
> --- On Sat, 4/3/10, Raymond O'Donnell <rod@iol.ie> wrote:
> On 03/04/2010 11:16, Dino Vliet wrote:
>
>> Hi postgresql list, If I have two tables with the same number of rows
>> but different columns and I want to create one table out of them what
>> would be the way to do that in postgresql?
>>
>> Table A has N number of rows and columns X,Y,Z and Table B has N
>> number of rows and P,Q,R as columns. None of the tables have a
>> column which can be used as a key.
>>
>> The resulting table should have N number of rows and X,Y,Z,P,Q,R as
>> columns.
>
> How do the rows in the tables relate to each other? You need to decide
> first how you match the rows in A and B.

> they don' t. It' s pure randomly generated data.

In that case, how about getting the cartesian product of the two tables,
and then LIMITing the result to N rows? - Something like this:

  select
    a.x, a.y, a.z,
    b.p, b.q, b.r
  from
    a, b
  limit N;

....substituting your value of N. It'll be slow if there are a lot of
rows in A and B, mind.

Ray.


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

Предыдущее
От: Dino Vliet
Дата:
Сообщение: Re: join two tables without a key
Следующее
От: Andreas Kretschmer
Дата:
Сообщение: Re: join two tables without a key