Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>WHERE works directly on the rows, that's also the reason why you can't specify column aliases in WHERE clause. It would cause an unknown column error.</p> <p>You could use HAVING or a subquery. In both cases the result will be calculated for all rows, then filtered.</p> <p><strong>UPDATE:</strong></p> <p>You have to filter by distance, right? So you can't filter rows first, then calculate distance. But what you can do, is to use the spatial extension. Then you'll have spatial indexes which could make your queries pretty fast, I guess (never had anything to do with things like this).</p> <p>Read more about it <a href="http://dev.mysql.com/doc/refman/5.0/en/spatial-extensions.html" rel="nofollow">here</a>.</p> <p><strong>UPDATE 2:</strong></p> <p>Actually I don't get what your question is at all. You want to order by something you have to calculate first. So what's the question? Will it be fast? I don't know. All I can tell is, that no index can be used since MySQL does not support indexes on calculated columns. Probably a temporary table to sort whatever data you're getting will be used, too, depends on how much data it is. I'd suggest <strong>try things out</strong>. </p> <p>Just do </p> <pre><code>SELECT coordA, coordB FROM whereever ORDER BY coordA - coordB </code></pre> <p>and that's it. When you have problems then, ask again. </p> <p>To filter later</p> <pre><code>SELECT * FROM ( SELECT coordA, coordB, coordA - coordB AS distance FROM whereever ORDER BY distance ) sq WHERE distance &gt; $foo </code></pre> <p>When that's too slow play around with indexes and/or the extension mentioned earlier. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload