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 -
fmauriAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Scott PletcherSenior DBACommented:
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
0
fmauriAuthor Commented:
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
0
fmauriAuthor Commented:
There are only 330 authors and 406 typists...
0
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

Scott PletcherSenior DBACommented:
Oops, sorry, use UNION instead of UNION ALL:

SELECT ...
UNION
SELECT ...
ORDER BY ...
0
fmauriAuthor Commented:
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...
0
Scott PletcherSenior DBACommented:
D'OH, VERY SORRY, I left the WHERE conditions off my queries.


SELECT prof.typist, 'Typist not in People'
FROM docsadm.profile prof
LEFT OUTER JOIN docsadm.people peop ON peop.system_id = prof.typist
WHERE peop.system_id IS NULL
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
WHERE auth.system_id IS NULL
ORDER BY 1
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
fmauriAuthor Commented:
No problem, it returned the correct results.

Thanks much for the speedy resolution, excellent job!

 - Frank-
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server

From novice to tech pro — start learning today.