Results 1 to 4 of 4
  1. #1
    Join Date
    Oct 2003
    Posts
    6

    Unanswered: No duplicate record from joined table

    Hi,
    I have 2 tables on DB2 version 6

    Tab_A
    ------------
    id name
    1 shop1
    2 shop2

    Tab_B
    -----------------------
    id_tab_a keyword
    1 book
    1 bookstore
    1 handbook
    2 restaurant

    I need to write a SQL query that find who have 'book' as keyword on Tab_B, but with no duplicated record. If i write:

    Select distinct id, name left join Tab_B on id=id_tab_a where
    keyword like '%book%'

    obtain 3 "duplicated" records.

    Any ideas?
    Thanks,
    Jhon

  2. #2
    Join Date
    Oct 2003
    Posts
    16

    Re: No duplicate record from joined table

    Originally posted by fartman
    Select distinct id, name left join Tab_B on id=id_tab_a where
    keyword like '%book%'
    You need to group this puppy

    select id,name from tab_a
    left join tab_b on id=id_tab_a
    group by id,name

    Best of luck
    -Chris
    Come read my SQL tutorial at http://www.bitesizeinc.net/index.php/sql.html

  3. #3
    Join Date
    Jul 2003
    Location
    india
    Posts
    15

    Re: No duplicate record from joined table

    HI, the following query will help you

    select id,name from tab_a
    left join tab_b on id=id_tab_a where keyword like '%book%'
    group by id,name;




    Originally posted by christodd
    You need to group this puppy

    select id,name from tab_a
    left join tab_b on id=id_tab_a
    group by id,name

    Best of luck
    -Chris
    Come read my SQL tutorial at http://www.bitesizeinc.net/index.php/sql.html

  4. #4
    Join Date
    Oct 2003
    Posts
    6

    Talking Re: No duplicate record from joined table

    problem solved !!!
    Thank you.

    Jhonny


    Originally posted by neelamchalam
    HI, the following query will help you

    select id,name from tab_a
    left join tab_b on id=id_tab_a where keyword like '%book%'
    group by id,name;

Posting Permissions

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