0

I am using the MySQL query to find distance between tow zip-codes when lat long is given.

SELECT postcode, ( 3959 * acos( cos( radians( 52.47592 ) ) * cos( radians( latitude ) ) * cos( radians( longitude ) - radians( -1.90539 ) ) + sin( radians( 52.47592 ) ) * sin( radians( latitude ) ) ) ) AS distance FROM ukpostcodes  HAVING distance <= 5 ORDER BY distance

it is working fine. But I want only postcode in result. I don't want distance column in result .

How can I achieve it.

Thanks

0

1 Answer 1

1
SELECT postcode FROM(
SELECT postcode, ( 3959 * acos( cos( radians( 52.47592 ) ) * cos( radians( latitude ) ) * cos( radians( longitude ) - radians( -1.90539 ) ) + sin( radians( 52.47592 ) ) * sin( radians( latitude ) ) ) ) AS distance FROM ukpostcodes  HAVING distance <= 5 ORDER BY distance
) AS tbl
Sign up to request clarification or add additional context in comments.

4 Comments

Thanks much. But I run this query it is showing this error . Every derived table must have its own alias.
@Rich5757: Give a name to the subquery. Something like as tbl at the very end of the query.
Just tbl. No need of double quotes.
@Raging-Bull: True that

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.