Welcome Guest, Not a member yet? Register   Sign In
SQL [Advanced, I think...]
#1

[eluser]Lewis Cowles[/eluser]
Hi so this is more about optimizing my SQL, than actual codeigniter, unless someone knows of a way to do this using codeigniter's in-built libraries and helpers more efficiently. It is worth noting that real-time data or as near as possible is a goal of the application I am working on so I think caching may produce undesirable effects.

I am running an SQL query to get the soonest appointment within a date range, that is also restricted by the distance between the postcode of the searcher and the postcode of the venue.

Code:
"SELECT postcodes.postcode, postcodes.id, available_venues.*, address_details.*, people.*, ( 3958.7558 * ACOS( COS( RADIANS( '%s' ) ) * COS( RADIANS( postcodes.latitude ) ) * COS( RADIANS( postcodes.longitude ) - RADIANS( '%s' ) ) + SIN( RADIANS( '%s' ) ) * SIN( RADIANS( postcodes.latitude ) ) ) ) AS distance FROM postcodes, people, available_venues, address_details HAVING distance < '%s' AND available_venues.availability > 0 AND available_venues.address_id = address_details.id AND address_details.postcode_id = postcodes.id AND available_venues.expert_id = people.id AND available_venues.date BETWEEN '%s' AND '%s' ORDER BY available_venues.date ASC, distance ASC LIMIT %s , %s"

so the above is my current query, I am currently using MyISAM, although as the relationships are defined in software, I suppose I should really use InnoDB? As you can probably tell i'm no db wizzard, please help lol


Messages In This Thread
SQL [Advanced, I think...] - by El Forum - 07-19-2012, 02:33 PM
SQL [Advanced, I think...] - by El Forum - 07-19-2012, 02:44 PM
SQL [Advanced, I think...] - by El Forum - 07-19-2012, 03:28 PM
SQL [Advanced, I think...] - by El Forum - 07-19-2012, 03:33 PM
SQL [Advanced, I think...] - by El Forum - 07-19-2012, 08:48 PM
SQL [Advanced, I think...] - by El Forum - 07-19-2012, 09:53 PM
SQL [Advanced, I think...] - by El Forum - 07-19-2012, 11:07 PM
SQL [Advanced, I think...] - by El Forum - 07-19-2012, 11:11 PM
SQL [Advanced, I think...] - by El Forum - 07-20-2012, 05:51 AM
SQL [Advanced, I think...] - by El Forum - 07-20-2012, 08:11 AM



Theme © iAndrew 2016 - Forum software by © MyBB