Last active
April 17, 2017 12:40
-
-
Save anoochit/48a98ffe3e09f43f79e7c753451fe911 to your computer and use it in GitHub Desktop.
nearby query from drupal fields, filter gender first and query nearby location
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT *,( 3959 * acos( cos( radians(13.785872) ) * cos( radians( field_location_lat ) ) * cos( radians( field_location_lng ) - radians(100.570635) ) + sin( radians(13.785872) ) * sin( radians( field_location_lat ) ) ) ) AS distance | |
FROM ( | |
SELECT users_field_data.uid,users_field_data.name, user__field_contact_line.field_contact_line_value,user__field_gender.field_gender_target_id,user__field_location.field_location_lat,user__field_location.field_location_lng | |
FROM users_field_data,user__field_contact_line,user__field_location,user__field_gender | |
WHERE users_field_data.status=1 | |
AND users_field_data.uid=user__field_contact_line.entity_id | |
AND users_field_data.uid=user__field_location.entity_id | |
AND users_field_data.uid=user__field_gender.entity_id | |
AND user__field_gender.field_gender_target_id=2 | |
) AS a | |
HAVING distance < 5 | |
ORDER BY distance | |
LIMIT 0,5 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment