title: Can "1054 Unknown column in order clause" be the result of an incorrectly killed mysql process?
body: <p>I just got a <code>1054 Unknown column x.y in order clause</code> error inside phpMyAdmin on a query where I did not expect it, because</p>
  
  <ul>
  <li>The query used did not contain an ORDER clause.</li>
  <li>The query used cannot be faulty since it works fine on a database with the identical table schema.</li>
  </ul>
  
  <p>The problem came up after I stopped a long running query by simply killing the mysql daemon from XAMPP Control panel.</p>
  
  <p>A <code>REPAIR TABLE x</code> didn't help. I got rid of the problem by explicitly querying the column that allegedly doesn't exist (<code>SELECT x.y FROM x</code>) and then doing my query again - which then worked.</p>
  
  <p><em>Is it possible that stopping the mysql process like I did is the reason for this symptom?</em></p>
  
  <p><strong>EDIT:</strong>
  The query that produced the said error:</p>
  
  <pre><code>SELECT * FROM x AS tblA
  
  INNER JOIN (
  
      SELECT z, y, COUNT(*) AS count
      FROM x
      GROUP BY z, y
      HAVING count &gt; 1
  
             ) tblB
  ON tblA.z = tblB.z AND tblA.y = tblB.y
  </code></pre>
  
  <p><strong>EDIT 2:</strong>
  The original query that was running on a 300k row table when I killed mysql:</p>
  
  <pre><code>SELECT * FROM x AS temp1
  
  INNER JOIN ( SELECT z, y, Count(*) AS count FROM x GROUP BY z, y HAVING Count &gt; 1 ) temp2
  ON temp1.z = temp2.z AND temp1.y = temp2.y
  
  RIGHT JOIN 
  (
  SELECT DISTINCT whole.v FROM x AS tblA
  
  INNER JOIN ( SELECT z, y, Count(*) AS count FROM x GROUP BY z, y HAVING Count &gt; 1 ) tblB
  ON tblA.z = tblB.z AND tblA.y = tblB.y
  
  RIGHT JOIN ( SELECT * FROM x ) whole
  ON tblA.v = whole.v AND tblA.w = whole.w
  
  WHERE tblA.v IS NULL
  ) temp3
  
  ON temp1.v != temp3.v
  </code></pre>