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

  • SEARCH
  • Home
  • 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 7960675
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T04:49:19+00:00 2026-06-04T04:49:19+00:00

We have the query: SELECT ID, MIN(SQRT(POW((100-x),2)) + POW((150-y),2)) AS distance FROM cabstands GROUP

  • 0

We have the query:

SELECT ID, MIN(SQRT(POW((100-x),2)) + POW((150-y),2)) AS distance 
FROM cabstands 
GROUP BY ID

to find out the ID of the closest point to the point 100, 150 in coordinate system. If I don’t request the ID and try to get just the distance, the query returns the true value. However, if I request the ID (as in above query) it returns all the points, because of the GROUP BY. If I don’t put GROUP BY, it simply doesn’t allow me to execute the query by saying:

ID is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.

What is the solution to my problem. Thanks in advance.

  • 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-04T04:49:20+00:00Added an answer on June 4, 2026 at 4:49 am

    You can use:

    SELECT TOP 1 ID, MIN(SQRT(POW((100-x),2)) + POW((150-y),2)) AS distance FROM cabstands GROUP BY ID ORDER BY distance ASC
    

    Or for MySQL:

    SELECT ID, MIN(SQRT(POW((100-x),2)) + POW((150-y),2)) AS distance FROM cabstands GROUP BY ID ORDER BY distance ASC LIMIT 1
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have query to find duplicate records : select min(a.rowindex)rowindx, b.rowindex rowindx1 from dedupinitial1
I have a query: select substr(name,7,50) as location, points,sum(if (p1=r1,10,-10))as total from dq.data group
I have the following query: SELECT MIN(myColumn) as myColumn FROM myTable WHERE date(time_stamp) =
I have this query select date(fecha) as day, min(num) as mi from myTable where
I have a query: select min(timestamp) from table This table has 60+million rows, and
I have a query as follows: WITH CTE AS ( SELECT MIN(att.Date) [minDate] FROM
I have a query: SELECT MIN(stat_md5) AS stat_md5 FROM (select * from ( mem_stat
I have this MySQL query that I'd like to optimize: SELECT min(`topic_id`) FROM `gallery_topics`
I have a query SELECT cd.signoffdate, min(cmp.dsignoff) as dsignoff FROM clients AS c LEFT
I have the following query. SELECT MIN(col1) FROM table1 WHERE id1 IN (SELECT id2

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.