Link to home
Start Free TrialLog in
Avatar of fmauri
fmauriFlag for United States of America

asked on

Query two SQl 2000 tables and find out which value is not in a particular table

I am trying to query two SQl 2000 tables and find out which value is not in a particular table.

The first table is called docsadm.people and contains columns named full_name and system_id

The second table is called docsadm.profile and contains columns named typist and author.

The docsadm.profile.typist and docsadm.profile.author columns have numeric values and reflect the values listed in the docsadm.people.system_id column.

I am trying to write a query that will tell me which docsadm.profile.typist and docsadm.profile.author value is not listed in the docsadm.people.system_id column.

Thanks for your assistance.  Frank -
Avatar of Scott Pletcher
Scott Pletcher
Flag of United States of America image

Something like this should do it:

SELECT prof.typist, 'Typist not in People'
FROM docsadm.profile prof
LEFT OUTER JOIN docsadm.people peop ON peop.system_id = prof.typist
UNION ALL
SELECT auth.author, 'Author not in People'
FROM docsadm.profile auth
LEFT OUTER JOIN docsadm.people peop ON peop.system_id = auth.author
ORDER BY 1
Avatar of fmauri

ASKER

It looks like it might of returned the correct results, how can I set the results to return distinct values. It returned over 1 million rows.

Thanks
Avatar of fmauri

ASKER

There are only 330 authors and 406 typists...
Oops, sorry, use UNION instead of UNION ALL:

SELECT ...
UNION
SELECT ...
ORDER BY ...
Avatar of fmauri

ASKER

I think we're getting a little closer. It only returned 736 rows but the data is not correct. I know the query should not return more than ten rows.

The query returns two columns, typist  and (No column name) which holds the 'Author not in People' and 'Typist not in People' values.

The typist column should be the system_id column and  should contain values where the docsadm.people.system_id column data is not in the docsadm.profile.author or docsadm.profile.typist column.

Hopefully I didn;'t confuse you.

Thanks...
ASKER CERTIFIED SOLUTION
Avatar of Scott Pletcher
Scott Pletcher
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of fmauri

ASKER

No problem, it returned the correct results.

Thanks much for the speedy resolution, excellent job!

 - Frank-