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. Query problem [modified]

Query problem [modified]

Scheduled Pinned Locked Moved Database
databasehelpsql-serversysadmin
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.
  • S Offline
    S Offline
    sujithkumarsl
    wrote on last edited by
    #1

    i am using sql server database please check the below table two columns say column A and Column B

    A B
    1 100
    1 200
    1 300
    2 100
    2 200
    3 100

    if the user give 100,200 and 300 i want return 1 ( which has all these values) if the user give 100 and 200 i have to give 1 and 2. Hope this is clear.... Please help me to build the query

    My small attempt...

    modified on Thursday, June 4, 2009 7:50 AM

    N 1 Reply Last reply
    0
    • S sujithkumarsl

      i am using sql server database please check the below table two columns say column A and Column B

      A B
      1 100
      1 200
      1 300
      2 100
      2 200
      3 100

      if the user give 100,200 and 300 i want return 1 ( which has all these values) if the user give 100 and 200 i have to give 1 and 2. Hope this is clear.... Please help me to build the query

      My small attempt...

      modified on Thursday, June 4, 2009 7:50 AM

      N Offline
      N Offline
      Niladri_Biswas
      wrote on last edited by
      #2

      Hello this time the question is not clear. Please be more specific. This is a very poor way of asking your question. Please define the function mapping your input to output more specifically Tell us the desired output. Is it For case 1: Input 100,200,300

      Output:

      A B

      1 100
      1 200
      1 300

      For Case 2: I/P: 100 , 200

      O/P:

      A B
      1 100
      1 200
      2 100
      2 200

      OR

      A B

      1 100
      2 200

      ? Please from next time whenever you post, give the sample output so that it will be easy to solve. Also, are you passing a comma delimited value or what? Nothing clear!: :( :)

      Niladri Biswas

      modified on Sunday, June 7, 2009 2:39 AM

      N 1 Reply Last reply
      0
      • N Niladri_Biswas

        Hello this time the question is not clear. Please be more specific. This is a very poor way of asking your question. Please define the function mapping your input to output more specifically Tell us the desired output. Is it For case 1: Input 100,200,300

        Output:

        A B

        1 100
        1 200
        1 300

        For Case 2: I/P: 100 , 200

        O/P:

        A B
        1 100
        1 200
        2 100
        2 200

        OR

        A B

        1 100
        2 200

        ? Please from next time whenever you post, give the sample output so that it will be easy to solve. Also, are you passing a comma delimited value or what? Nothing clear!: :( :)

        Niladri Biswas

        modified on Sunday, June 7, 2009 2:39 AM

        N Offline
        N Offline
        Niladri_Biswas
        wrote on last edited by
        #3

        Anyway Assuming that For case 1:

        Input 100,200,300

        Output:

        A B

        1 100
        1 200
        1 300

        Solution SELECT MIN(A), B FROM tbl_test WHERE B IN (100, 200, 300) GROUP BY B; For Case 2:

        I/P: 100 , 200

        O/P:

        A B
        1 100
        1 200
        2 100
        2 200

        Solution is SELECT A, B FROM tbl_test WHERE B IN (100, 200) ORDER BY A, B; hope this helps. And vote me :) And from next time please define the function mapping your input to output more specifically :)

        Niladri Biswas

        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