title: MySQL: Get only objects with currently not active plan
body: <p>I want to create a query that gets me only those object ids, who belog to a plan that's current status is quitted (-1). This can be done via the begin field, but i don't know how to exclude past quitted plans. Of course there can be many plans and many objects. I trimmed the original structure down to this:</p>
  
  <pre><code>TABLE objects
  --------------------
  id, title, xid, state
  1, a, 6, 1
  2, b, 6, 1
  3, c, 6, 1
  4, d, 2, 1
  
  TABLE plans
  --------------------
  xid, status, begin
  6, 1, 2017
  2, -1, 2017
  6, -1, 2016
  </code></pre>
  
  <p>This query gets all objects that have a plan which status is quitted (-1).
  Problem is, that this query also gets all objects ids if the quitted plan lies in the past and the current active plan ist fine.</p>
  
  <pre><code>SELECT o.id
  FROM objects AS o
  LEFT JOIN plans AS p ON o.xid=p.xid
  WHERE p.status = -1
  ORDER BY p.begin
  </code></pre>
  
  <p>This outputs:
  1,2,3,4
  But it should only output
  4</p>
  
  <p>I want this because in the end i want a query that deactivates (o.state=0) all objects that currently don't have an active plan.</p>