Results 1 to 5 of 5
  1. #1
    Join Date
    Nov 2006
    Posts
    11

    Unanswered: select any 2 numbers (was "help")

    I have a table that have ID_Number,Telephone_Number,Contract_No and Telephone_Type. lets say one id_number has one contract_no with different telephone_numbers and Telephone_Type so now what i wanna know is how can i select any 2 numbers if i have more that 3 per id_number in my table bear in mind that my table has about 200 000 rows.
    example:

    ID_Number Tel_Number Contract_No Tel_Type
    123 555-22 5 home
    123 444-12 5 Business
    123 546-12 5 Cell

  2. #2
    Join Date
    Feb 2003
    Location
    India
    Posts
    216
    it is not important how many rows your table is having execpt for performance and disk-space issues, it is important how you want the output. what I understand that you want any two numbers from a set.

    select top 2 * from table1 where ID_Number = 123

  3. #3
    Join Date
    Nov 2006
    Posts
    11

    select any two numbers

    it is not important how many rows your table is having execpt for performance and disk-space issues, it is important how you want the output. what I understand that you want any two numbers from a set.

    select top 2 * from table1 where ID_Number = 123


    i dont think help bcoz you have about +-150000 id number

  4. #4
    Join Date
    Nov 2006
    Location
    UK
    Posts
    46
    How about that?

    Code:
    select ID_Number,
           Tel1 = max(Tel_Number),
           Tel2 = min(Tel_Number)
    from TheTable
    --where ID_Number = 123
    group by ID_Number
    Regards
    Kris Zywczyk

  5. #5
    Join Date
    Feb 2003
    Location
    India
    Posts
    216
    sorry, i believe that your requirement was not clear to me. however, if u r seeking to get a result set that will contain only 2 enrties (rows) per ID_Number from the whole table then u can try something like below. note that it assumes that the table is having a unique key (referred in the SQL as PK)

    Code:
    select * from table1 as t1 where t1.PK in (select top 2 PK from table1 where table1.ID_Number=t1.ID_Number)
    if this is again something that is not what you expect, please elaborate your output with an example and without getting angry

Posting Permissions

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