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.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Sub-query help

Author  Topic 

SpeshulK926
Starting Member

16 Posts

Posted - 2008-09-19 : 16:44:18
I have 2 tables, Red and Blue (easier to read than table1, table2, etc). In each table, I have 1 column, emailaddress.

The query is off of the Blue Table. I need it to only list the ones in the Blue table where the e-mail address doesn't exist in the Red table. If the e-mail address exists in the red table, it needs to not show up. I got really confused half-way through and just need some insight.

Here's the query I got so far, please be kind...

select distinct(b.emailaddress) from blue b
where not exists (select null from red r
where b.emailaddress = r.emailaddress)
order by b.emailaddress

I can't tell if this is right or if this is everything...

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-09-20 : 01:47:58
[code]SELECT b.*
FROM Blue b
LEFT JOIN Red r
ON r.emailaddress=b.emailaddress
WHERE r.emailaddress IS NULL[/code]
or

[code]SELECT *
FROM Blue
WHERE emailaddress NOT IN
(SELECT emailaddress FROM Red)[/code]
Go to Top of Page
   

- Advertisement -