If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ANSI SQL > No duplicate record from joined table

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-08-03, 12:37
fartman fartman is offline
Registered User
 
Join Date: Oct 2003
Posts: 6
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
Reply With Quote
  #2 (permalink)  
Old 10-08-03, 19:04
christodd christodd is offline
Registered User
 
Join Date: Oct 2003
Posts: 16
Re: No duplicate record from joined table

Quote:
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
Reply With Quote
  #3 (permalink)  
Old 10-09-03, 00:47
neelamchalam neelamchalam is offline
Registered User
 
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;




Quote:
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
Reply With Quote
  #4 (permalink)  
Old 10-10-03, 12:16
fartman fartman is offline
Registered User
 
Join Date: Oct 2003
Posts: 6
Talking Re: No duplicate record from joined table

problem solved !!!
Thank you.

Jhonny


Quote:
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;
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On