If you have, for example;

WHERE line = min( (SELECT length FROM lines) ) 
      AND number < 500;

(It's just an example, not a real code)

How does PostgreSQL react when the result from the MIN has a number > 500 ? Is he then going after the second MIN or what happens ?


What do you mean by line = length?

I guess what you mean is that your subquery will find the id of the shortest line. Then you ask in the outer query for a line with that id and some number less than 500. If the shortest line then have a a number that is more than 500 you will get nothing back.


Something like this should work if I understand you right.

SELECT DISTINCT ON (id) id , geom
FROM lines_table 
WHERE some_number < 500 
ORDER BY id, ST_Length(geom);
  • thank you! and how can I achieve this? Select the line with the highest length, but with other conditions (like the number <500, for example) – user28088 Mar 26 '14 at 17:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.