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 > SQL help

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-21-05, 18:00
Dipanjan Dipanjan is offline
Registered User
 
Join Date: Sep 2003
Posts: 84
SQL help

Say I have got table1 - col1,col2,col3. Table 2 is exactly same. How do I find out the values of col1 from table 1 which has got the same number of rows in both table1 and table2.I want to establish this in one single query.
Reply With Quote
  #2 (permalink)  
Old 01-21-05, 18:26
sathyaram_s sathyaram_s is offline
Super Moderator
 
Join Date: Aug 2001
Location: UK
Posts: 4,534
An example will help explain your question better ...

Thanks

Sathyaram
__________________
Visit the new-look IDUG Website , register to gain access to the excellent content.
Reply With Quote
  #3 (permalink)  
Old 01-21-05, 18:30
Marcus_A Marcus_A is offline
Registered User
 
Join Date: May 2003
Location: USA
Posts: 5,196
Not sure if this is valid sytax with the "having" clause, but give it a try:

select a.col1, count(*) from table1 a
group by a.col1
having count(*) = (select count(*) from table2 b where b.col1 = a.col1)
__________________
M. A. Feldman
IBM Certified DBA on DB2 for Linux, UNIX, and Windows
IBM Certified DBA on DB2 for z/OS and OS/390

Last edited by Marcus_A; 01-21-05 at 18:35.
Reply With Quote
  #4 (permalink)  
Old 01-22-05, 09:23
sathyaram_s sathyaram_s is offline
Super Moderator
 
Join Date: Aug 2001
Location: UK
Posts: 4,534
That's a valid syntax ... Checked in V8.2

Cheers
Sathyaram
__________________
Visit the new-look IDUG Website , register to gain access to the excellent content.
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