Welcome Guest, Not a member yet? Register   Sign In
Joined Min/Max and 'Having'

(02-24-2015, 01:39 AM)ridley1012 Wrote: More a programming issue rather than a codeigniter issue. Got a bit of an issue with using 'Having' and joined tables. It works but its horrendously slow, looking for any input that may speed it up.

Don;t put any tables into the min/max aggregation that you don't need there. In an aggregation (GROUP BY) query, every field returned must either be part of the GROUP BY or an aggregation field so if you include 5 lines of address, the customer name, favorite color etc.. then these must all be part of the GROUP BY which will cause it to be slow.

I would do this as a 2 part query.
The first part just gets the min/max rental records that you are interested in - you will need to include some sort of key back into the source tables if you need to get back at the hire reference. The second part would then link to the hirer, address, card payment etc.

I don't know if you can do this with the active record pattern, you might need to hand write the full query and than pass it as a complete SQL statement

Messages In This Thread
Joined Min/Max and 'Having' - by ridley1012 - 02-24-2015, 01:39 AM
RE: Joined Min/Max and 'Having' - by obiron - 02-24-2015, 05:46 AM

Theme © iAndrew 2016 - Forum software by © MyBB