Results 1 to 2 of 2
  1. #1
    Join Date
    Apr 2007
    Posts
    130

    Unanswered: How to do the query over two tables

    Hello ALL,

    I would like to get a list of persons who ever borrowed book more than once in a month by querying the following two tables.

    tb1
    Code:
    Name   Class
    Bob     A
    John    B
    Mary   B
    Winston C
    Lee     C
    tb2
    Code:
    Name  Month  BorrowedBookName
    Bob    Jan         bookname1
    Bob    Jan         bookname2
    Mary  Feb         bookname3
    Mary  Feb         bookname4
    Mary  Feb         bookname5
    Winston Mar      bookname6
    John   Aug.       bookname7
    John   Aug.       bookname8
    Thanks
    Last edited by cy163; 10-16-08 at 00:15.

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    Code:
    SELECT DISTINCT name
      FROM (
           SELECT name
                , month
             FROM tb2
           GROUP
               BY name
                , month
           HAVING COUNT(*) > 1
           ) AS d
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

Posting Permissions

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