Groups > Interbase > Interbase SQL > Re: How to select records not present in either two similar tables




Re: How to select records not present in either two similar
tables

Re: How to select records not present in either two similar tables
20 Nov 2007 13:23:17 -0700
Please do not multipost or cross post your messages. It violates
Borland's guidelines for using their newsgroups and wastes everyone's
time. Please post one message in the most appropriate newsgroup and
please take a moment to read the newsgroup guidelines at
http://info.borland.com/newsgroups/guide.html

-- 
Post Reply
How to select records not present in either two similar tables
Tue, 20 Nov 2007 21:10:38 +010
In my IB db I've two big employees tables whith the same structure and  
keys. I need to create a query to select the employees present in the  
Post Reply
Re: How to select records not present in either two similar tables
Tue, 20 Nov 2007 23:00:34 -060
To do queries like that, you can use the IN and NOT IN.

select * from EMPLOYEETABLE1 where EMPLOYEEID NOT IN (select EMPLOYEEID from 
EMPLOYEETABLE2)

Here's a few more examples of usage:

// selects all contacts which have not been assigned to a group
select CONTACTID from CONTACTS where CONTACTID NOT IN (select CONTACTID from 
CONTACTGROUPMEMBERS)

or

// selects all contacts which are in a group
select CONTACTID from CONTACTS where CONTACTID IN (select CONTACTID from 
CONTACTGROUPMEMBERS)

- Jason

"Leonardo Tansini" <ltansini@katamail.com> wrote in message 
news:op.t13wz0jinnuxdn@salaxp...
> In my IB db I've two big employees tables whith the same structure and 
> keys. I need to create a query to select the employees present in the 
> first table that are not present in the second one. Some help? Regards. 
Post Reply
Re: How to select records not present in either two similar tables
Wed, 21 Nov 2007 09:23:59 +010
Uzytkownik "Jason Summers" <jason@grinc.org> napisal w
wiadomosci 
news:4743bb74$1@newsgroups.borland.com...
> To do queries like that, you can use the IN and NOT IN.
>
> select * from EMPLOYEETABLE1 where EMPLOYEEID NOT IN (select EMPLOYEEID 
> from EMPLOYEETABLE2)
>
> Here's a few more examples of usage:
>
> // selects all contacts which have not been assigned to a group
> select CONTACTID from CONTACTS where CONTACTID NOT IN (select CONTACTID 
> from CONTACTGROUPMEMBERS)
>
> or
>
> // selects all contacts which are in a group
> select CONTACTID from CONTACTS where CONTACTID IN (select CONTACTID from 
> CONTACTGROUPMEMBERS)
>
> - Jason
>
> "Leonardo Tansini" <ltansini@katamail.com> wrote in message

> news:op.t13wz0jinnuxdn@salaxp...
>> In my IB db I've two big employees tables whith the same structure and

>> keys. I need to create a query to select the employees present in the 
>> first table that are not present in the second one. Some help?
Regards.


above will be very slow on big tables
better is

select * from EMPLOYEETABLE1 E1 where
not exists(select FROM EMPLOYEETABLE2 E2 WHERE E1.EMPLOYEEID=E2.EMPLOYEEID)


Karol Bieniaszewski 

Post Reply
Re: How to select records not present in either two similar tables
25 Nov 2007 00:11:17 -0700
"Leonardo Tansini" <ltansini@katamail.com> wrote:
>In my IB db I've two big employees tables whith the same structure and  
>keys. I need to create a query to select the employees present in the  
>first table that are not present in the second one. Some help? Regards.

ANS--->
    suppose first table name is emp1 & second one is emp2 then you query
should be like---------

SELECT  emp1.emp_name, emp1.address FROM emp1, emp2
WHERE emp1.emp_id=emp2.emp_id;

It's too simple.
Post Reply
<< Previous 1 2 Next >>
( Page 1 of 2 )
about | contact