Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
Mike_h
Starting Member
7 Posts |
Posted - 2007-10-17 : 09:04:52
|
Hi.. I was wondering how to join two tables together but only return the values that are in one table and not the other with the select statementE.gt1 t21 1 2 234I would like the output of my query to output only 3 and 4 they are present in t1 but not t2Is there a some sort of join that allows me to do this? |
|
Kristen
Test
22859 Posts |
Posted - 2007-10-17 : 09:09:21
|
See: http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=91107 |
 |
|
Mike_h
Starting Member
7 Posts |
Posted - 2007-10-17 : 09:20:50
|
select t1.a from t1 left outer join t2 on t1.a = t2.awould give me all four records.An inner join would give me records 1 and 2However i need to get records 3 and 4 returned as they are not present in t2? |
 |
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2007-10-17 : 09:46:32
|
[code]select t1.a from t1 left outer join t2 on t1.a = t2.awhere t2.a is null[/code] KH[spoiler]Time is always against us[/spoiler] |
 |
|
Kristen
Test
22859 Posts |
Posted - 2007-10-17 : 12:55:12
|
Ah, sorry. You are in need of a NOT EXISTS. Which you can do in the WHERE clause; or you can use an OUTER JOIN and test for NULL as khtan has shown.Kristen |
 |
|
Kristen
Test
22859 Posts |
Posted - 2007-10-17 : 12:56:00
|
An example might help!select t1.a from t1 WHERE NOT EXISTS (SELECT * FROM t2 WHERE t1.a = t2.a) Kristen |
 |
|
|
|
|