Re: How can we match a condition among 2 diff. tables? - Mailing list pgsql-sql

From Peter Eisentraut
Subject Re: How can we match a condition among 2 diff. tables?
Date
Msg-id Pine.LNX.4.30.0107131816250.677-100000@peter.localdomain
Whole thread Raw
In response to How can we match a condition among 2 diff. tables?  (bhuvansql@yahoo.com)
List pgsql-sql
bhuvansql@yahoo.com writes:

>  Now, i need to get the details of all employees who did
>  receive NONE of the salesorders. ie.. i wish to select the
>  records of table 'employee' whose 'emp_id' are not
>  there in table 'salesorder'.

SELECT * FROM employee WHERE emp_id NOT IN (SELECT emp_id FROM salesorder);

or, slightly uglier but possibly faster

SELECT * FROM employee WHERE NOT EXISTS   (SELECT 1 FROM salesorder WHERE salesorder.emp_id = employee.emp_id);

-- 
Peter Eisentraut   peter_e@gmx.net   http://funkturm.homeip.net/~peter



pgsql-sql by date:

Previous
From: Stephan Szabo
Date:
Subject: Re: Date Validation?
Next
From: A_Schnabel@t-online.de (Andre Schnabel)
Date:
Subject: Re: How can we match a condition among 2 diff. tables?