[Webinar] Streamline your web hosting managementRegister Today

x
?
Solved

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

Posted on 2008-01-28
7
Medium Priority
?
272 Views
Last Modified: 2008-01-28
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 -
0
Comment
Question by:fmauri
  • 4
  • 3
7 Comments
 
LVL 70

Expert Comment

by:Scott Pletcher
ID: 20761883
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
 

Author Comment

by:fmauri
ID: 20761952
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
 

Author Comment

by:fmauri
ID: 20761983
There are only 330 authors and 406 typists...
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
LVL 70

Expert Comment

by:Scott Pletcher
ID: 20762078
Oops, sorry, use UNION instead of UNION ALL:

SELECT ...
UNION
SELECT ...
ORDER BY ...
0
 

Author Comment

by:fmauri
ID: 20762583
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
 
LVL 70

Accepted Solution

by:
Scott Pletcher earned 2000 total points
ID: 20762795
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
 

Author Comment

by:fmauri
ID: 20762894
No problem, it returned the correct results.

Thanks much for the speedy resolution, excellent job!

 - Frank-
0

Featured Post

Learn to develop an Android App

Want to increase your earning potential in 2018? Pad your resume with app building experience. Learn how with this hands-on course.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Windocks is an independent port of Docker's open source to Windows.   This article introduces the use of SQL Server in containers, with integrated support of SQL Server database cloning.
What we learned in Webroot's webinar on multi-vector protection.
Planning to migrate your EDB file(s) to a new or an existing Outlook PST file? This video will guide you how to convert EDB file(s) to PST. Besides this, it also describes, how one can easily search any item(s) from multiple folders or mailboxes…
SQL Database Recovery Software repairs the MDF & NDF Files, corrupted due to hardware related issues or software related errors. Provides preview of recovered database objects and allows saving in either MSSQL, CSV, HTML or XLS format. Ensures recov…
Suggested Courses

591 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question