Results 1 to 11 of 11
  1. #1
    Join Date
    Aug 2009
    Posts
    73

    Unanswered: Pls Help With this Query

    Table A

    ID-----------NUMBER--------Type
    1------------1415----------xyz
    1------------2-------------PQR
    1------------5------------oops
    3------------6-------------XYZ
    4------------1415-----------ooPS

    i want to pull ID,Type from table A where Number is 1415 exclusively and result shud Be


    ID-----------NUMBER--------Type

    4------------1415-----------ooPS

  2. #2
    Join Date
    Nov 2004
    Location
    on the wrong server
    Posts
    8,835
    Provided Answers: 6
    umm Have you read about SELECT?
    “If one brings so much courage to this world the world has to kill them or break them, so of course it kills them. The world breaks every one and afterward many are strong at the broken places. But those that will not break it kills. It kills the very good and the very gentle and the very brave impartially. If you are none of these you can be sure it will kill you too but there will be no special hurry.” Earnest Hemingway, A Farewell To Arms.

  3. #3
    Join Date
    Aug 2009
    Posts
    73
    Yes i have and i have near about million rows in this table

  4. #4
    Join Date
    Aug 2009
    Posts
    73
    Table A

    ID-----------NUMBER--------Type
    1------------1415----------xyz
    1------------2-------------PQR
    1------------5------------oops
    3------------6-------------XYZ
    4------------1415-----------ooPS

    :
    :
    :
    :

    1000000------- 1415-----------cas

    i want to pull ID,Type from table A where Number is 1415 exclusively and result shud Be


    ID-----------NUMBER--------Type

    4------------1415-----------ooPS
    :
    :
    :
    :
    :
    1000000------- 1415-----------cas


    i want all the records like 4 , 1000000 which are only associated with Number 1415 and not with another number

  5. #5
    Join Date
    Jul 2011
    Posts
    63
    Quote Originally Posted by amitwadhawan123 View Post
    Table A

    ID-----------NUMBER--------Type
    1------------1415----------xyz
    1------------2-------------PQR
    1------------5------------oops
    3------------6-------------XYZ
    4------------1415-----------ooPS

    :
    :
    :
    :

    1000000------- 1415-----------cas

    i want to pull ID,Type from table A where Number is 1415 exclusively and result shud Be


    ID-----------NUMBER--------Type

    4------------1415-----------ooPS
    :
    :
    :
    :
    :
    1000000------- 1415-----------cas


    i want all the records like 4 , 1000000 which are only associated with Number 1415 and not with another number
    SELECT column_name(s)
    FROM table_name
    WHERE column_name IN (value1,value2,...)

    SQL IN Operator

  6. #6
    Join Date
    Aug 2009
    Posts
    73
    I cannot use In clause, as i have more than million records

  7. #7
    Join Date
    Jul 2011
    Posts
    63
    Quote Originally Posted by amitwadhawan123 View Post
    I cannot use In clause, as i have more than million records
    How about the like clause?

    SELECT *
    FROM table_name
    WHERE column_name like '1415'

  8. #8
    Join Date
    Mar 2007
    Location
    Holmestrand, Norway
    Posts
    332
    Or even better:
    Code:
    SELECT *
    FROM table_name
    WHERE column_name = '1415'
    Like is for pattern matching, = is for exact match.
    Ole Kristian Velstadbråten Bangås - Virinco - MSSQL.no - Facebook - Twitter

  9. #9
    Join Date
    Aug 2009
    Posts
    73
    @Roac it wont work because it will pull up record with ID=1 too.....i need all ID's which are having Number 1415 and not related to any other number

    in my question ID=1 is having Number 1415, 2,5......so i dont need it in my output

  10. #10
    Join Date
    Mar 2007
    Location
    Holmestrand, Norway
    Posts
    332
    Something like this then:
    Code:
    SELECT *
    FROM table_name t1
    WHERE column_name = '1415' and not exist (select * from table_name t2 where t1.id = t2.id and column_name <> '1415')
    Ole Kristian Velstadbråten Bangås - Virinco - MSSQL.no - Facebook - Twitter

  11. #11
    Join Date
    Aug 2009
    Posts
    73
    @Roac...Thanks!!!!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •