Micro blog about Answer to the Ultimate Question of Life, the Universe, and Everything
  • Home
    • List all categories
    • Sitemap
  • Downloads
    • WebSphere
    • Hitachi902
    • Hospital
    • Kryptonite
    • OCR
    • APK
  • About me
    • Gallery
      • Italy2022
      • Côte d'Azur 2024
    • Curriculum vitae
      • Resume
      • Lebenslauf
    • Social networks
      • Facebook
      • Twitter
      • LinkedIn
      • Xing
      • GitHub
      • Google Maps
      • Sports tracker
    • Adventures planning
  1. You are here:  
  2. Home
  3. MySQL
  4. MySQL

Finding locations that are within a certain radius distance

Details
Written by: Stanko Milosev
Category: MySQL
Published: 12 January 2020
Last Updated: 12 January 2020
Hits: 2443
This example I took from here. In my case I will display markers that are in distance of 25 kilometers from Longitude = 7 and Latitude = 50.
SELECT id, Longitude, Latitude, ( 3959 * acos( cos( RADIANS(50) ) * cos( radians( Latitude ) ) * cos( radians( Longitude ) - radians(7) ) + sin( RADIANS(50) ) * sin( radians( Latitude ) ) ) ) AS distance FROM gpslocation HAVING distance < 25 ORDER BY DISTANCE LIMIT 0 , 20;

Notice that number 50 is twice mentioned in query.

Windows 7.

Details
Written by: Stanko Milosev
Category: MySQL
Published: 17 September 2010
Last Updated: 30 November -0001
Hits: 8147

If you can't connect to MySQL over PHP from your localhost, then try something like:


In the Windows/System32/drivers/etc/hosts file remove the entry like this: 
::1             localhost 


and make sure you still have: 
127.0.0.1       localhost


Taken from here.

Union count.

Details
Written by: Stanko Milosev
Category: MySQL
Published: 20 August 2008
Last Updated: 30 November -0001
Hits: 6619

Question is, how to get count records in union query?

For example, we have this query:

select count(*) from hdxbh_content
union all
select count(*) from tnyg_users

As a result, we will have two records:

 

count(*)
904 
1 


And we want to get result as one record, 905, how?

Like this:

select ((select count(*) from hdxbh_content) + (select count(*) from tnyg_users)) count

Taken from here.