Solved

simple (I hope) SQL question

Posted on 2014-11-04
4
139 Views
Last Modified: 2014-11-06
hello,
just a simple question (I hope).
I've 2 tables (say table1 and table2) both have a common column (say "cf") but the first table has in this column more values than the second (aka the first table have more records than the second).
I'd like to extract all the data of the first table whose cf values (i.e. table1.cf) are NOT present on the second table (i.e. are NOT in table2.cf)

thanks a lot for your help,
fabiano
0
Comment
Question by:fabianope65
4 Comments
 
LVL 26

Assisted Solution

by:Shaun Kline
Shaun Kline earned 167 total points
ID: 40422154
select *
from table1
where not exists (select 1 from table2 where cf = table1.cf)
0
 
LVL 58

Accepted Solution

by:
Gary earned 166 total points
ID: 40422156
SELECT * FROM table1 WHERE cf NOT IN (SELECT cf FROM table2)

Open in new window

0
 
LVL 11

Assisted Solution

by:John_Vidmar
John_Vidmar earned 167 total points
ID: 40422835
SELECT	*
FROM	table1	a
LEFT
JOIN	table2	b	ON	a.cf = b.cf
WHERE	b.cf IS NULL

Open in new window

0
 

Author Closing Comment

by:fabianope65
ID: 40425684
Thanks to all of You,
See You,
Fabiano
0

Featured Post

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Loops and updating in SQL Query 9 52
Complex SQL statement in VB.NET 7 31
SQL Recursion 6 16
SQL - Curser to do an insert based on a select 2 6
If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

809 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