Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Select where table1 not in table2

Posted on 2006-07-20
3
Medium Priority
?
775 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

Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

Question has a verified solution.

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

In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
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.
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.

636 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