Click here to Skip to main content
15,072,134 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Given two tables -

t1 -

Col1
a
b
c
d
e

t2 -

Col1
a
b
c

What would the select/query statement look like to just return values d and e from t1.
Do I need a join?

Thanks
Posted

1 solution

Try this:
SQL
SELECT Col1
FROM t1
WHERE Col1 NOT IN (SELECT Col1 FROM t2)


For further information, please see:
Using UNION, EXCEPT and INTERSECT with Other Transact-SQL Statements[^]
IN (T-SQL)[^]
   
v2
Comments
Sergey Alexandrovich Kryukov 17-Feb-14 13:18pm
   
Sure, a 5.
—SA
Maciej Los 17-Feb-14 13:22pm
   
Thank you, Sergey ;)
Congrats for new positioin in your job!
Sergey Alexandrovich Kryukov 17-Feb-14 15:05pm
   
It's not new... But thank you...
—SA
Maciej Los 17-Feb-14 15:13pm
   
If it's not new, anything has changed?
Sergey Alexandrovich Kryukov 17-Feb-14 15:15pm
   
Changed... yes, probably: I just visited LinkedIn, if this is what you looked at... :-)
—SA
Maciej Los 17-Feb-14 16:33pm
   
;)
enipla 17-Feb-14 15:20pm
   
Thanks, that did it.
Maciej Los 17-Feb-14 16:33pm
   
You're very welcome ;)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900