title: SQLAlchemy NOT exists on subselect?
body: <p>I'm trying to replicate this raw sql into proper sqlalchemy implementation but after a lot of tries I can't find a proper way to do it:</p>
  
  <pre class="lang-sql prettyprint-override"><code>SELECT *
  FROM images i
  WHERE NOT EXISTS (
      SELECT image_id
      FROM events e
      WHERE e.image_id=i.id AND e.chat_id=:chat_id)
  ORDER BY random()
  LIMIT 1
  </code></pre>
  
  <p>Closest I got is:</p>
  
  <pre><code>session.query(Image).filter(and_(Event.image_id == Image.id, Event.chat_id == chat_id)).order_by(func.random()).limit(1)
  </code></pre>
  
  <p>But I cant seem to find how to put the NOT EXISTS clause.</p>
  
  <p>Can anyone lend a helping hand?</p>
  
  <p>Thanks!</p>