简体   繁体   中英

SQL query issue - Unknown column error

I'm trying to select db records based on wordpress custom fields that hold lat and long and have hit a brick wall on this query. Anyone see anything obvious that i'm overlooking?

Thanks!

WordPress database error: [Unknown column 'latitude.meta_value' in 'field list']

SELECT p.ID, p.post_title, (( ACOS( SIN( 39.1749 * PI() / 180 ) 
    * SIN( `latitude.meta_value` * PI() / 180 ) 
    + COS( 39.1749 * PI() / 180 ) 
    * COS( `latitude.meta_value` * PI() / 180 ) 
    * COS(( -94.5804 - `longitude.meta_value` ) * PI() / 180 )) * 180 / PI() ) * 60 * 1.1515 ) AS distance 
FROM wp_posts p 
LEFT JOIN wp_postmeta latitude ON latitude.post_id = p.ID AND latitude.meta_key = 'neighborly_issue_lat' 
LEFT JOIN wp_postmeta longitude ON longitude.post_id = p.ID AND longitude.meta_key = 'neighborly_issue_lng' HAVING distance < 10;

Yours commas are wrong, try with :

   SELECT p.ID, p.post_title, (( ACOS( SIN( 39.1749 * PI() / 180 ) 
* SIN( `latitude`.`meta_value` * PI() / 180 ) 
+ COS( 39.1749 * PI() / 180 ) 
* COS( `latitude`.`meta_value` * PI() / 180 ) 
* COS(( -94.5804 - `longitude`.`meta_value` ) * PI() / 180 )) * 180 / PI() ) * 60 * 1.1515 ) AS distance

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM