Find the not included

-- Find those addid in the employe table, which is not in the address table:
select addid from
	(select distinct addid from employe) e
where addid not in (
	select a.addid from address a
	inner join
	(select distinct addid from employe) e
	on a.addid = e.addid
)

-- same as
select distinct addid from employe
where addid not in (select addid from address)

-- nulls can be a problem. If all values are wanted,
-- which is not in the address table then use this:
select addid from employe
where (
	addid not in (select addid from address where addid is not null))
	or
	addid is null
)

-- then there is also this:
-- select de rækker i employe, der ikke er i address tabellen
select e.* from employe e
left join address a on e.addid = a.addid 
where a.addid is null
Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: