Results 1 to 4 of 4

Thread: Distinct?

  1. #1
    Join Date
    Jul 2013
    Posts
    8

    Unanswered: Distinct?

    Hai rather new to DB2

    i have a table A that has three fields

    terminal-id
    product-id
    office-number

    terminal/product is primary key

    How can I quickly find out if there is more than one office-number related to a terminal-id?
    example

    row 1
    terminal A
    product GTA
    office 1245

    row 2
    terminal A
    product SDG
    office 1249

    Here two offices are related two the same terminal

    thnx

  2. #2
    Join Date
    Jan 2003
    Posts
    4,292
    Provided Answers: 5
    Select terminal_id,count(*) from mytable group by terminal_id


    Andy

  3. #3
    Join Date
    Jul 2013
    Posts
    8
    In the situation beneath only office 1245 is related to terminal A
    The count(*) will give me the value 2, which is wrong

    row 1
    terminal A
    product GTA
    office 1245

    row 2
    terminal A
    product SDG
    office 1245

  4. #4
    Join Date
    Jan 2003
    Posts
    4,292
    Provided Answers: 5
    Select terminal_id,count(distinct office) from mytable group by terminal_id

    Andy

Posting Permissions

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