SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 Script Library
 Help with an SQL script
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

LarryShilling
Starting Member

1 Posts

Posted - 08/23/2011 :  11:51:57  Show Profile  Reply with Quote
I have a couple of tables that are linked in a one to many type of connection. That is, for every record in Table A there could be multiple records in Table B. I'm writing an SQL query that joins the two tables. I'm trying to select records in Table A where one of the fields in Table B is NOT EQUAL TO a value.

My problem is that as long as ONE of the joined records in Table B isn't that value, the record in Table A is selected.

Is there a WHERE EVERY clause which would exclude the record in Table A even if ONE of the records in Table B had the field with the value??

I hope that was clear.

visakh16
Very Important crosS Applying yaK Herder

India
52317 Posts

Posted - 08/23/2011 :  12:01:11  Show Profile  Reply with Quote
you can implement it like

SELECT a.columns...
FROM TableA a
JOIN (SELECT RelatedCol
      FROM TableB
      GROUP BY RelatedCol
      HAVING SUM(CASE WHEN yourField= <your value> THEN 1 ELSE 0 END) =0)b
ON b.RelatedCol = a.RelatedCol


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000