Solved

simple (I hope) SQL question

Posted on 2014-11-04
4
131 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 25

Assisted Solution

by:Shaun Kline
Shaun Kline earned 167 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Thanks to all of You,
See You,
Fabiano
0

Featured Post

Get up to 2TB FREE CLOUD per backup license!

An exclusive Black Friday offer just for Expert Exchange audience! Buy any of our top-rated backup solutions & get up to 2TB free cloud per system! Perform local & cloud backup in the same step, and restore instantly—anytime, anywhere. Grab this deal now before it disappears!

Join & Write a Comment

Foreword This is an old article.  Instead of using the MySQL extension that was used in the original code examples, please choose one of the currently supported database extensions instead.  More information is available here: MySQLi / PDO (http://…
Composite queries are used to retrieve the results from joining multiple queries after applying any filters. UNION, INTERSECT, MINUS, and UNION ALL are some of the operators used to get certain desired results.​
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

763 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now