title: oracle sql - find common items purchased between two users
body: <p>Item - Id, Name,<br>
  PurchaseLog - Id, ItemId, CustomerId, PurchaseDate
  User - Id, UserName</p>
  
  <p>For given two customer's usernams, find names of common items they purchased within last year. </p>
  
  <p>Is this naive (or even correct)? : </p>
  
  <pre><code>select distinct item.id, item.name
  from item i, PurchaseLog log_username1, PurchaseLog log_username2,  user user1, user user2
  where lower(user1.username) = lower('UserName1') AND
        lower(user2.username) = lower('UserName2') AND
        log_username1.itemid = log_username2.itemid AND
        log_username2.itemid = i.itemid AND
        log_username1 &gt;-- satisfy date contraint AND
        log_username2 &gt;-- satisfy date contraint
  </code></pre>