MySQL Forums
Forum List  »  Newbie

Re: Reversing the output of a query
Posted by: Danny Dahl
Date: September 09, 2024 10:58AM

The issue with your query is in the way you're ordering by 'index'. In SQL, single quotes ' ' are used for string literals, not for column names. To order by the column properly, you need to remove the quotes around 'index'.

Here’s the corrected query:

sql
Copy code
SELECT *,
( 3959 * acos ( cos ( radians(38.764104) ) * cos( radians(latitude ) ) * cos( radians(longitude ) - radians(16.199104) ) + sin ( radians(38.764104) ) * sin( radians(latitude ) ) ) ) AS distance
FROM banner
HAVING distance < 0.3
ORDER BY `index` ASC;
If index is a reserved keyword or causing issues, you can try using backticks ( ) around it as shown. If not, simply use:

sql
Copy code
ORDER BY index ASC;
This should now order your results in ascending order.

Options: ReplyQuote


Subject
Written By
Posted
Re: Reversing the output of a query
September 09, 2024 10:58AM


Sorry, only registered users may post in this forum.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.