Results 1 to 3 of 3
  1. #1
    Join Date
    Jul 2002
    Posts
    227

    Unanswered: how to avoid duplicate record...

    Hi, I've table T1.

    ID.......DESC_ID
    1..........aa
    1..........gg
    2..........bb
    3..........cc
    3..........ff
    4..........dd


    table T2:

    ID.......DESC_ID
    1..........aa
    1..........gg
    2..........bb
    3..........cc
    3..........ff
    4..........dd


    select distinct a.id,b.desc_id
    from T1 a, T2 b
    where a.ID = b.id

    output is:

    ID.......DESC_ID
    1..........aa
    1..........gg
    2..........bb
    3..........cc
    3..........ff
    4..........dd

    But I'd like to get just one ID, not duplicate ID

    How can I write my query to get just one record for ID?

    as like (for example):

    ID.......DESC_ID
    1..........gg
    2..........bb
    3..........ff
    4..........dd


    Thanks in advance!

  2. #2
    Join Date
    Jul 2003
    Posts
    2,296
    How do you know WHICH id you want?
    Is there a rule of some kind?
    - The_Duck
    you can lead someone to something but they will never learn anything ...

  3. #3
    Join Date
    Sep 2002
    Location
    UK
    Posts
    5,171
    Provided Answers: 1
    It looks like you want this:
    Code:
    select a.id, max(b.desc_id)
    from T1 a, T2 b
    where a.ID = b.id
    group by a.id;

Posting Permissions

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