?
Solved

Select where table1 not in table2

Posted on 2006-07-20
3
Medium Priority
?
771 Views
Last Modified: 2012-05-05
I have 2 tables.

Table1 is made of 2 primary keys, table_id and job_id along with a bunch of other values (lets just use job_name for now).
Table2 is made of 2 primary keys, table_id and job_id along with a bunch of other values (Don't care what for this example).

I need to select the job_name from table1 where that entries table_id and job_id are not in table2.

How can I do this?  I was using an outter join when I wanted table 2 with table 1 but now that I only want table1 when there is no matchig entry in table 2!!

Thanks!
0
Comment
Question by:JRamos1200
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 25

Accepted Solution

by:
Mr_Peerapol earned 500 total points
ID: 17147254
SELECT t1.*
FROM Table1 t1
WHERE NOT EXISTS (SELECT 1 FROM Table2 t2 WHERE t1.table_id = t2.table_id AND t1.job_id = t2._jobid)
0
 

Author Comment

by:JRamos1200
ID: 17147495
That did it!  Thanks.  What does select 1 mean anyway?
0
 
LVL 25

Expert Comment

by:Mr_Peerapol
ID: 17147523
Just the constant number 1. In the EXISTS clause the list of fields returned by inner SELECT doesn't matter because EXISTS() just checks whether there is a record returned by the SELECT statement no matter what columns included.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
Via a live example, show how to shrink a transaction log file down to a reasonable size.
Suggested Courses

762 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