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,
JhonOriginally 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|||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|||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;
Monday, March 26, 2012
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment