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 > Database Server Software > DB2 > need help on selecting distinct values

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 11-11-09, 06:24
lifzgud lifzgud is offline
Registered User
 
Join Date: Sep 2009
Posts: 6
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?
Reply With Quote
  #2 (permalink)  
Old 11-11-09, 06:34
sathyaram_s sathyaram_s is offline
Super Moderator
 
Join Date: Aug 2001
Location: UK
Posts: 4,534
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.
Reply With Quote
  #3 (permalink)  
Old 11-11-09, 08:02
DB2Plus DB2Plus is offline
Registered User
 
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
Reply With Quote
  #4 (permalink)  
Old 11-11-09, 09:33
Stealth_DBA Stealth_DBA is offline
Registered User
 
Join Date: May 2009
Posts: 472
lifzgud, Here is another way:

Code:
SELECT X
FROM A
WHERE EXISTS(SELECT *
             FROM B
             WHERE A.Y = B.Y
            )
Reply With Quote
  #5 (permalink)  
Old 11-11-09, 09:55
Lenny77 Lenny77 is offline
Registered User
 
Join Date: Jul 2009
Location: NY
Posts: 886
Question Looks good

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

Lenny
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