Trouble with IN operator
-
Hi All consider Table # tblTest fldMainId fldSubID 1 A 1 B 1 C 2 A 2 B 3 A Here I have written Query : Select fldMainid from tblTest where fldSubID IN (A,B) This gives Result fldMainId's : 1,2 and 3 How can I write query so that only fldMainid which has A,B strictly is choosen.So here 1 will not be choosen since it has C also, and 3 is not choosen since it has no A Hence only 2 is choosen as it has A and B. Navneet.H
Develop2Program & Program2Develop
-
Hi All consider Table # tblTest fldMainId fldSubID 1 A 1 B 1 C 2 A 2 B 3 A Here I have written Query : Select fldMainid from tblTest where fldSubID IN (A,B) This gives Result fldMainId's : 1,2 and 3 How can I write query so that only fldMainid which has A,B strictly is choosen.So here 1 will not be choosen since it has C also, and 3 is not choosen since it has no A Hence only 2 is choosen as it has A and B. Navneet.H
Develop2Program & Program2Develop
In T-SQL you can use this query: Select fldMainId from tblTest where fldSubID='A' Intersect Select fldMainId from tblTest where fldSubID='B' Except Select fldMainId from tblTest where fldSubID='C' If you have more possibilities for fldSubID then either you will have to write longer query or use subquery
#region signature my articles #endregion
-
In T-SQL you can use this query: Select fldMainId from tblTest where fldSubID='A' Intersect Select fldMainId from tblTest where fldSubID='B' Except Select fldMainId from tblTest where fldSubID='C' If you have more possibilities for fldSubID then either you will have to write longer query or use subquery
#region signature my articles #endregion
Hi GD, Thank's a bunch , I will try it out and let you know. thank's again
Develop2Program & Program2Develop