Results 1 to 5 of 5
  1. #1
    Join Date
    Sep 2009
    Posts
    6

    Unanswered: need help on selecting distinct values

    Hi,
    I have two tables a and b

    Table a

    x y
    1 a
    2 b

    Table b

    y z
    a alpha
    a bravo


    When i do select a.x from a,b where a.y=b.y it will return me
    1
    1

    I need only distinct values without using the distinct command.
    How is this possible?

  2. #2
    Join Date
    Aug 2001
    Location
    UK
    Posts
    4,650
    Why don't you want to use distinct ????
    What version, platform, fixpak of db2 are you on ?

    Looks like an assignment question ..
    Visit the new-look IDUG Website , register to gain access to the excellent content.

  3. #3
    Join Date
    Jul 2009
    Posts
    150

    Lightbulb using GROUP BY

    Quote Originally Posted by lifzgud View Post
    Hi,
    I have two tables a and b

    Table a

    x y
    1 a
    2 b

    Table b

    y z
    a alpha
    a bravo


    When i do select a.x from a,b where a.y=b.y it will return me
    1
    1

    I need only distinct values without using the distinct command.
    How is this possible?
    Code:
    select a.x from a,b where a.y=b.y
    GROUP BY  a.x
    Kara

  4. #4
    Join Date
    May 2009
    Posts
    508
    Provided Answers: 1
    lifzgud, Here is another way:

    Code:
    SELECT X
    FROM A
    WHERE EXISTS(SELECT *
                 FROM B
                 WHERE A.Y = B.Y
                )

  5. #5
    Join Date
    Jul 2009
    Location
    NY
    Posts
    963

    Question Looks good

    Code:
    select a.x 
    from a 
    where a.y in (select y from b)
    Also looks good...

    Lenny

Posting Permissions

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