Re: How can we match a condition among 2 diff. tables?

Поиск
Список
Период
Сортировка
От Peter Eisentraut
Тема Re: How can we match a condition among 2 diff. tables?
Дата
Msg-id Pine.LNX.4.30.0107131816250.677-100000@peter.localdomain
обсуждение исходный текст
Ответ на How can we match a condition among 2 diff. tables?  (bhuvansql@yahoo.com)
Список 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 по дате отправления:

Предыдущее
От: Stephan Szabo
Дата:
Сообщение: Re: Date Validation?
Следующее
От: A_Schnabel@t-online.de (Andre Schnabel)
Дата:
Сообщение: Re: How can we match a condition among 2 diff. tables?