• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Query translation in Active Record format

#1
[eluser]Alhazred[/eluser]
How to write this query in Active Record format?
Code:
SELECT c.id AS id,c.name AS name,t.name AS category
FROM category c, type t
WHERE t.id = c.category
ORDER BY c.name

#2
[eluser]Alhazred[/eluser]
Here what I've tried
Code:
$this->db->select('c.id AS id, c.name AS name, t.name AS category');
$this->db->from('category c, tipo_category t');
$this->db->where('t.id','c.category');

$result = $this->db->get();
I don't have any error, but that generates an empty result, while the SQL version finds 3 records.

#3
[eluser]Aken[/eluser]
Try:

Code:
$this->db->where('t.id = c.category');

#4
[eluser]Alhazred[/eluser]
Thenks, it works.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.