• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
using LIKE in SQL query with activerecord

#4
[eluser]xzela[/eluser]
You've got some interesting SQL there. I can help you make the SQL statement run better by not concatenating tables.

Try something like this:

SQL:
Code:
SELECT  
  p1.id,
  p1.name
FROM
  product_p1,
WHERE
  p1.id='".$idProd."'
  AND p1.id NOT IN (SELECT id FROM p2)
  AND p1.tags = p2.tags --//the like is unnecessary here (you're comparing two columns directly)
You may not be able to like two column like this.
Active Record:
Code:
$this->db->select('p1.id, p1.name');
$this->db->from('product_p1');
$this->db->where('p1.id', $idProd);
$this->db->where('p1.id', 'NOT IN (SELECT id FROM p2', FALSE);
$this->db->where('p1.tags', 'p2.tags');
$query = $this->db->get();


Messages In This Thread
using LIKE in SQL query with activerecord - by El Forum - 02-04-2009, 02:11 PM
using LIKE in SQL query with activerecord - by El Forum - 02-04-2009, 04:38 PM
using LIKE in SQL query with activerecord - by El Forum - 02-04-2009, 05:02 PM
using LIKE in SQL query with activerecord - by El Forum - 02-04-2009, 05:24 PM
using LIKE in SQL query with activerecord - by El Forum - 02-04-2009, 06:20 PM
using LIKE in SQL query with activerecord - by El Forum - 02-04-2009, 06:44 PM
using LIKE in SQL query with activerecord - by El Forum - 02-04-2009, 10:29 PM

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


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