Search Postgresql Archives

Re: Question About UNION

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



David Wilson wrote:
On Thu, Oct 9, 2008 at 3:31 PM, Bill Thoen <bthoen@xxxxxxxxxx> wrote:

Thanks, but that didn't work. That selected only the records from table1.

That's why I warned you about it being written in gmail. :)
I'm sorry, you had it right the first time. Here's a script that verifies it:

create table table1 (
  a integer,
  b integer,
  c char(1)
);

insert into table1 values ( 1, 12, 'A');
insert into table1 values ( 2, 16, 'B');
insert into table1 values ( 8,  6, 'A');
insert into table1 values (19,  9, 'C');
insert into table1 values (20, 12, 'A');

create table table2 (
  a integer,
  b integer,
  c char(1)
);

insert into table2 values ( 1, 13, 'D');
insert into table2 values ( 2, 16, 'B');
insert into table2 values ( 8,  6, 'B');
insert into table2 values (12,  5, 'A');

select * from table1
union
select table2.* from table2 left join table1 on table2.a=table1.a and
table2.b=table1.b where table2.a is null;

drop table table1;
drop table table2;



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux