Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9184785
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T19:08:20+00:00 2026-06-17T19:08:20+00:00

I have two columns of x,y coordinates in a table on a Postgres database.

  • 0

I have two columns of x,y coordinates in a table on a Postgres database.

I can find the extremes in x and y using:

select min(x), max(x), min(y), max(y)
from coords

How do assign these to variables something like this:

select min(x) as xmin, max(x) as xmax, min(y) as ymin, max(y) as ymax
from coords

to achieve

select y
from coords
where x = xmin

etc…to obtain the four extreme points in the half-billion row dataset? (the point of the exercise)

the desired select statement works but I can’t use the “where” clause as it says that xmin is not a column. What is the correct approach, or in the unlikely event that I am using the correct approach, what is the correct syntax?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T19:08:21+00:00Added an answer on June 17, 2026 at 7:08 pm

    One way is with a join and subquery:

    select c.*
    from coords c join
         (select min(x) as xmin, max(x) as xmax, min(y) as ymin, max(y) as ymax
          from coords
         ) clim
         on c.x in (clim.xmin, clim.xmax) or c.y in (clim.ymin, clim.ymax)
    

    Another way to do this is with window functions:

    select c.*
    from (select c.*,
                 least(row_number() over (order by x),
                       row_number() over (order by x desc),
                       row_number() over (order by y),
                       row_number() over (order by y desc)
                      ) as seqnum
          from coords c
         ) c
    where seqnum = 1
    

    And another way, if you really want just 4 points is:

    select * from coords order by x limit 1 union all
    select * from coords order by x desc limit 1 union all
    select * from coords order by y limit 1 union all
    select * from coords order by y desc limit 1
    

    With such a large number of rows, these will all run faster if you have indexes on x and y. In this case, the last is probably the fastest.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two columns(column1, column2) in my oracle database table named as demo .
I have two columns. People have to select elements from the first column and
I have two columns say Main and Sub . (they can be of same
I have two columns in my table and the rows are created dynamically. <table
I have two columns in my Items table 'Category', 'Category2', the two columns contain,
I have two columns in the table hours at sea - Would be good
I have two columns in my table profile which are id and education .
I have a table with two relevant columns, an ID and a VARRAY of
I have an Access 2010 database with information from Geonames. The table name is
I have two columns in a table. Without explicitly specifying a column width, I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.