MS SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesMS SQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old July 14th, 2008, 09:26 PM
bhaarat bhaarat is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2004
Posts: 192 bhaarat User rank is Lance Corporal (50 - 100 Reputation Level)bhaarat User rank is Lance Corporal (50 - 100 Reputation Level)bhaarat User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 1 Day 17 h 6 m 45 sec
Reputation Power: 5
Sql query help not exists

Hello,

I have two tables A & B. table A has a column for example Color. There are some rows in this table that have value '-2' for Column color.

There is another table B.

Two tables can be joined by column called 'Sample'.

I am trying to find out a way to fetch records that have value of -2 in table A for column Color but these records are NOT IN table B.

I'd appreciate if someone could help me with this a little.

I tried something like this

Code:

select * from table A where A.Color = '-2' and not exists (select * from table B);


but that doesnt work

Reply With Quote
  #2  
Old July 14th, 2008, 09:56 PM
r937's Avatar
r937 r937 is offline
SQL Consultant
Click here for more information.
 
Join Date: Feb 2003
Location: Toronto Canada
Posts: 17,912 r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level) 
Time spent in forums: 1 Month 4 Weeks 12 h 17 m 55 sec
Reputation Power: 1018
Code:
SELECT tableA.* 
  FROM tableA 
LEFT OUTER
  JOIN tableB
    ON tableB.Sample = tableA.Sample
 WHERE tableA.Color = '-2' 
   AND tableB.Sample IS NULL
__________________
r937.com | rudy.ca

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesMS SQL Development > Sql query help not exists


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway