Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Trouble with IN operator

Trouble with IN operator

Scheduled Pinned Locked Moved Database
databasequestion
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    Navneet Hegde
    wrote on last edited by
    #1

    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

    G 1 Reply Last reply
    0
    • N Navneet Hegde

      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

      G Offline
      G Offline
      Giorgi Dalakishvili
      wrote on last edited by
      #2

      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

      N 1 Reply Last reply
      0
      • G Giorgi Dalakishvili

        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

        N Offline
        N Offline
        Navneet Hegde
        wrote on last edited by
        #3

        Hi GD, Thank's a bunch , I will try it out and let you know. thank's again

        Develop2Program & Program2Develop

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups