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 |
LarryShilling
Starting Member
1 Post |
Posted - 2011-08-23 : 11:51:57
|
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
52326 Posts |
Posted - 2011-08-23 : 12:01:11
|
you can implement it likeSELECT a.columns...FROM TableA aJOIN (SELECT RelatedCol FROM TableB GROUP BY RelatedCol HAVING SUM(CASE WHEN yourField= <your value> THEN 1 ELSE 0 END) =0)bON b.RelatedCol = a.RelatedCol ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
|
|
|
|
|