{"id":7282,"date":"2014-06-03T23:34:59","date_gmt":"2014-06-03T23:34:59","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/06\/03\/count-query-returning-unexpected-results-collection-of-common-programming-errors\/"},"modified":"2014-06-03T23:34:59","modified_gmt":"2014-06-03T23:34:59","slug":"count-query-returning-unexpected-results-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/06\/03\/count-query-returning-unexpected-results-collection-of-common-programming-errors\/","title":{"rendered":"Count query returning unexpected results-Collection of common programming errors"},"content":{"rendered":"<p>I have this query:<\/p>\n<pre><code>SELECT\n    count(*) as count ,\n    ( 3959 * acos(\n        cos( radians( 37.774929 ) ) * cos( radians( lat ) ) * cos( radians( lng ) - radians( -122.419418 ) )\n        + sin( radians( 37.774929 ) ) * sin( radians( lat ) )\n    ) ) AS distance\nFROM users\nHAVING distance &lt; 150\n<\/code><\/pre>\n<p>I thought it was going to give me the count of users who are in the radius of 150 miles. But instead it gave me a total number of users. And if lat\/lng were different, it would give me zero number of users when there were some users there.<\/p>\n<p>Any ideas how to change this query in order to get the number of users within the 150mi radius?<\/p>\n<p>Thanks!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I have this query: SELECT count(*) as count , ( 3959 * acos( cos( radians( 37.774929 ) ) * cos( radians( lat ) ) * cos( radians( lng ) &#8211; radians( -122.419418 ) ) + sin( radians( 37.774929 ) ) * sin( radians( lat ) ) ) ) AS distance FROM users HAVING distance &lt; [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-7282","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/7282","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=7282"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/7282\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=7282"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=7282"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=7282"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}