title: Delete rows in database where id not found in a filtered query in Flask-SQLAlchemy
body: <p>I'd like to remove rows in my database where an ID is not found amongst ID's from a filtered query. In layman's term, &quot;Delete rows if the row's ID is not amongst ID's sourced from a query that kept unique users by name&quot;.</p>
  <p>For example, I would like to clear out users in my database with duplicate names:</p>
  <pre class="lang-py prettyprint-override"><code>from project.models import db, User
  
  query = User.query.group_by(User.name)
  User.query.filter(** filter out User.id not found in `query.id` **).delete()
  db.session.commit()
  </code></pre>