pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feedMINUS emulation?
3+ messages / 3 participants
[nested] [flat]
* MINUS emulation?
@ 1999-12-20 01:47 Barry Baldwin <bbaldwin@indyme.com>
0 siblings, 2 replies; 3+ messages in thread
From: Barry Baldwin @ 1999-12-20 01:47 UTC (permalink / raw)
To: pgsql-sql
Hi all,
I'm trying to do a query that returns all the records in one table unless
they exist in another table.
For example the first query I tried was this;
Select A.field_id, A.data, B.field_id, B.data
from table_1 A, table_2 B
where A.field_id <> B.field_id;
This query resulted in no records being returned, I believe this is because
Table_2 is empty.
I then tried :
Select field_id, data
from table_1
minus
Select field_id, data
from table_2;
This didn't work because the Minus directive isn't recognized.
Does anyone have a suggestion on how I might accomplish this?
TIA,
Barry
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: [SQL] MINUS emulation?
@ 1999-12-20 02:18 tjk@tksoft.com <tjk@tksoft.com>
parent: Barry Baldwin <bbaldwin@indyme.com>
1 sibling, 0 replies; 3+ messages in thread
From: tjk@tksoft.com @ 1999-12-20 02:18 UTC (permalink / raw)
To: bbaldwin@indyme.com; +Cc: pgsql-sql
Barry,
> I'm trying to do a query that returns all the records in one table unless
> they exist in another table.
This implies you need this:
Select A.field_id, A.data, B.field_id, B.data
from table_1 A, table_2 B where A.field_id not in
(select A.field_id from table_1 A, table_2 B where
A.field_id = B.field_id);
Troy
>
> Hi all,
>
> I'm trying to do a query that returns all the records in one table unless
> they exist in another table.
>
> For example the first query I tried was this;
>
> Select A.field_id, A.data, B.field_id, B.data
> from table_1 A, table_2 B
> where A.field_id <> B.field_id;
>
> This query resulted in no records being returned, I believe this is because
> Table_2 is empty.
>
> I then tried :
>
> Select field_id, data
> from table_1
> minus
> Select field_id, data
> from table_2;
>
> This didn't work because the Minus directive isn't recognized.
>
> Does anyone have a suggestion on how I might accomplish this?
>
> TIA,
>
> Barry
>
>
> ************
>
>
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: [SQL] MINUS emulation?
@ 1999-12-20 03:10 Tom Lane <tgl@sss.pgh.pa.us>
parent: Barry Baldwin <bbaldwin@indyme.com>
1 sibling, 0 replies; 3+ messages in thread
From: Tom Lane @ 1999-12-20 03:10 UTC (permalink / raw)
To: Barry Baldwin <bbaldwin@indyme.com>; +Cc: pgsql-sql
Barry Baldwin <bbaldwin@indyme.com> writes:
> Select field_id, data
> from table_1
> minus
> Select field_id, data
> from table_2;
The SQL standard spelling for this is "EXCEPT", not "MINUS".
regards, tom lane
^ permalink raw reply [nested|flat] 3+ messages in thread
end of thread, other threads:[~1999-12-20 03:10 UTC | newest]
Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
1999-12-20 01:47 MINUS emulation? Barry Baldwin <bbaldwin@indyme.com>
1999-12-20 02:18 ` tjk@tksoft.com <tjk@tksoft.com>
1999-12-20 03:10 ` Tom Lane <tgl@sss.pgh.pa.us>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox