Please start any new threads on our new site at We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Save Password
Forgot your Password?

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

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.

Very Important crosS Applying yaK Herder

52326 Posts

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

SELECT a.columns...
FROM TableA a
      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

Go to Top of Page
  Previous Topic Topic Next 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.02 seconds. Powered By: Snitz Forums 2000