Advertisement
vojtarek

Untitled

Jun 2nd, 2011
463
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
SQL 0.45 KB | None | 0 0
  1. -- select URL entities, not yet downloaded
  2. -- entity id + lowest pubDate, pubTime of its' instances
  3. SELECT
  4. e.id,
  5. e.name,
  6. d.pubDate,
  7. d.pubTime
  8. FROM entities e, instances i, documents d
  9. WHERE
  10. e.id=(
  11.     SELECT ee.id
  12.     FROM entities ee
  13.     WHERE ee.enttype_id=9
  14.         AND NOT EXISTS (SELECT * FROM downloadurl WHERE entity_id=ee.id)
  15.     LIMIT 1
  16.     )
  17. AND i.entity_id=e.id -- JOIN
  18. AND i.item_id=d.id   -- JOIN
  19. ORDER BY (d.pubDate + d.pubTime)
  20. LIMIT 1;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement