Results 1 to 4 of 4

Thread: SQL help

  1. #1
    Join Date
    Sep 2003
    Posts
    84

    Unanswered: 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.

  2. #2
    Join Date
    Aug 2001
    Location
    UK
    Posts
    4,650
    An example will help explain your question better ...

    Thanks

    Sathyaram
    Visit the new-look IDUG Website , register to gain access to the excellent content.

  3. #3
    Join Date
    May 2003
    Location
    USA
    Posts
    5,737
    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)
    Last edited by Marcus_A; 01-21-05 at 19:35.
    M. A. Feldman
    IBM Certified DBA on DB2 for Linux, UNIX, and Windows
    IBM Certified DBA on DB2 for z/OS and OS/390

  4. #4
    Join Date
    Aug 2001
    Location
    UK
    Posts
    4,650
    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.

Posting Permissions

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