Re: Help with two table query - Mailing list pgsql-general

From Darren Ferguson
Subject Re: Help with two table query
Date
Msg-id Pine.LNX.4.10.10202251031150.15152-100000@thread.crystalballinc.com
Whole thread Raw
In response to Help with two table query  (Joost Kraaijeveld <J.Kraaijeveld@Askesis.nl>)
List pgsql-general
SELECT orderManager,salesItemType,priority
FROM table 2
WHERE orderManager NOT IN (SELECT orderManager
                           FROM table1);

This will give you the result you are looking for.

Note i made the assumption that both orderManager fields are the same
datatype

Darren Ferguson

On Sat, 23 Feb 2002, Joost Kraaijeveld wrote:

> Hi everyone,
>
> I have two tables. I want get all the rows (orderManagers) that are in table
> 2 that are not in table 1.
>
> Table 1 has the following columns:
>     district
>     orderManager
>     salesItemType
>     priority
>
> Table 2 has the following columns:
>     orderManager
>     salesItemType
>     priority
>
> The query I came up with is:
>
> SELECT Table2.orderManager FROM Table1, Table2
>             WHERE
>             Table1.district  = '1990-01-01-00-02-04-000001'
>             AND
>             Table1.salesItemType  = '1990-01-01-00-02-16-000001'
>
>             AND
>             Table2.salesItemType  = '1990-01-01-00-02-16-000001'
>
>             AND
>             Table1.orderManager  != Table2.orderManager
>
> But this query does not produce the expected result. The query just returns
> all orderManagers from Table2 that have the required salesItemType.
>
> Can anyone help me with this?
>
> TIA
>
> Joost
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 2: you can get off all lists at once with the unregister command
>     (send "unregister YourEmailAddressHere" to majordomo@postgresql.org)
>


pgsql-general by date:

Previous
From: Devrim GUNDUZ
Date:
Subject: Re: install psql 7.1.3 - rh6.2 - libreadline.so.4
Next
From: Tom Lane
Date:
Subject: Re: Need to vacuum multiple times for effectiveness?