LordZardeck
LordZardeck

Reputation: 8283

Error in distance SQL query

I have this SQL query:

SELECT 
  *, 
  6371.04 * acos(cos(pi() / 2 - radians(90 - `Tournament`.`latitude`)) * cos(pi() / 2 - radians(90 - 37.226)) * cos(radians(`Tournament`.`longitude`) - radians(-93.4397)) + sin(pi() / 2 - radians(90 - `Tournament`.`latitude`)) * sin(pi() / 2 - radians(90 - 37.226))) AS `Tournament`.`dist` 
FROM `tournaments` AS `Tournament`   
WHERE 1 = 1   
ORDER BY `Tournament`.`dist` ASC  
LIMIT 5

I can't figure out what could be possibly wrong with that statement. Here's the error I'm getting:

1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '.`dist` FROM `tournaments` AS `Tournament`   WHERE 1 = 1   ORDER BY `Tournament`' at line 1

Could anyone point me in the right direction?

Upvotes: 0

Views: 71

Answers (2)

Ray Toal
Ray Toal

Reputation: 88378

The keyword AS is supposed to be followed by an id, not a compound identifier.

From the manual:

A select_expr can be given an alias using AS alias_name. The alias is used as the expression's column name and can be used in GROUP BY, ORDER BY, or HAVING clauses.

http://dev.mysql.com/doc/refman/5.0/en/select.html

More on alias names: http://dev.mysql.com/doc/refman/5.6/en/identifiers.html

Upvotes: 2

Matt
Matt

Reputation: 1242

AS `Tournament`.`dist`

It is probably complaining about the dot. Try assigning it to just dist.

Upvotes: 1

Related Questions