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 8349147
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T07:54:32+00:00 2026-06-09T07:54:32+00:00

With the help of StackOverflow I have a MySQL query that works. After making

  • 0

With the help of StackOverflow I have a MySQL query that works. After making a few changes it returns zip and distance. I been trying to make a Function to set parameters for the given lat and lng values and return the zip from the other table. However the query returns two values, I only need one.

SELECT loc.zip,(((ACOS(SIN((lat*PI()/180)) * SIN((`latitude`*PI()/180))+COS((lat*PI()/180)) * COS((`latitude`*pi()/180)) * COS(((lng - `longitude`)*PI()/180))))*180/PI())*60*1.1515) AS `distance` FROM geov1.zcta loc HAVING distance < 5 LIMIT 1;

So far this is what I have as my Function:

BEGIN
DECLARE lat VARCHAR(15);
DECLARE lng VARCHAR(15);
DECLARE zip BIGINT;

SET zip = SELECT loc.zip,(((ACOS(SIN((lat*PI()/180)) * SIN((`latitude`*PI()/180))+COS((lat*PI()/180)) * COS((`latitude`*pi()/180)) * COS(((lng - `longitude`)*PI()/180))))*180/PI())*60*1.1515) AS `distance` FROM geov1.zcta loc HAVING distance < 5 LIMIT 1;

RETURN zip;

END

This does not work, give me and error that there is some wrong in line 10 which is this:

`longitude`)*PI()/180))))*180/PI())*60*1.1515) AS `distance` FROM geov1.zcta loc HAVING distance < 5 LIMIT 1;

At this point I am at a loss, I just need to have the query return the zip with the given coordinates. Thank you for the help.

  • 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-09T07:54:33+00:00Added an answer on June 9, 2026 at 7:54 am

    If your SELECT statement returns two values, then you should use SELECT statement with INTO clause, e.g. –

    BEGIN
      DECLARE a, b INT;
      SELECT MIN(column1), MAX(column1) INTO a,b FROM table;
    END
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Dear gods of Stackoverflow Let's say I have a MySQL query that selects a
Now that I have decided upon Firebird , with the help of StackOverflow :),
Help me, Stackoverflow! I have a simple .NET 3.5 console app that reads some
Please help Stackoverflow! I have a MapInterface class in AS3 that inherits from Interface
Help me Stackoverflow! So, I feel that I have set up my environment correctly
with the help of resources of stackoverflow, i have managed to make autocomplete on
Dear Friends from Stackoverflow, Please help me with a problem that i'm having when
The majority of my questions I've asked here so far on StackOverflow have been
I found the following in Stackoverflow and have been working with it to find
I have been working with Java and Xml for a few months now, and

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.