Welcome Guest, Not a member yet? Register   Sign In
$this->db->orderby ?
#8

[eluser]kgill[/eluser]
For those who are telling him ORDER BY doesn't work like that, ordinarily you'd be right if we're talking standards but MySQL went rogue and actually allows expressions in the order by clause so it will work but only if you're using MySQL (which somewhat defeats the purpose of bothering to use active record but that's beside the point).

Now that said I tested the following query and it works, so if you're getting errors when you convert it to AR, then AR is screwing it up when it builds the SQL (enable profiling to verify):
Code:
select *
from companies
WHERE area = 'london'
AND category = 'builders'
AND status = 'active'
ORDER BY sub_area=‘brent’ DESC, sub_area desc
limit 1, 10

if you're using any other DB you have to resort to unions and place holder columns:
Code:
select 1, companies.*
from companies
WHERE area = 'london'
AND category = 'builders'
AND status = 'active'
and sub_area = 'brent'
union
select 2, companies.*
from companies
WHERE area = 'london'
AND category = 'builders'
AND status = 'active'
and sub_area <> 'brent'
order by 1, sub_area desc

As for what's faster, using $this->db->query is always going to be faster because you aren't messing around with all the functions calls for constructing the SQL for you but the speed trade off isn't going to be anything you will notice so basically you're pointlessly optimizing.


Messages In This Thread
$this->db->orderby ? - by El Forum - 03-09-2010, 06:03 AM
$this->db->orderby ? - by El Forum - 03-09-2010, 07:13 AM
$this->db->orderby ? - by El Forum - 03-09-2010, 07:17 AM
$this->db->orderby ? - by El Forum - 03-09-2010, 07:22 AM
$this->db->orderby ? - by El Forum - 03-09-2010, 10:05 AM
$this->db->orderby ? - by El Forum - 03-09-2010, 12:50 PM
$this->db->orderby ? - by El Forum - 03-09-2010, 01:05 PM
$this->db->orderby ? - by El Forum - 03-09-2010, 02:50 PM
$this->db->orderby ? - by El Forum - 03-09-2010, 03:14 PM
$this->db->orderby ? - by El Forum - 03-09-2010, 03:48 PM
$this->db->orderby ? - by El Forum - 03-09-2010, 05:36 PM
$this->db->orderby ? - by El Forum - 03-09-2010, 07:52 PM



Theme © iAndrew 2016 - Forum software by © MyBB