Welcome Guest, Not a member yet? Register   Sign In
SQL subquery using active record
#1

[eluser]Raymondddd[/eluser]
Hi,

I need to use a subquery to get the information i want. Currently im using active record for my query so i use this method: http://shawnmccool.com/2009/09/18/using-...ubqueries/

My subquery:
Code:
$this->db->select('f.price');
$this->db->from('product_price AS f');
$this->db->where('f.product_id', 'p.product_id');


p.product_id comes from my main query. This is not working because active record sees 'p.product_id' as a string. But this have to be the id from my main query.

When i output the whole query you also see the quotes:
Code:
SELECT `p`.`product_id`, `p`.`product_name`, `p`.`product_image`, `p`.`product_model`, (SELECT `f`.`price`
FROM (`product_price` AS f)
WHERE `f`.`product_id` = 'p.product_id') as test
FROM (`product` AS p)
WHERE `p`.`product_id` = 692

I need to remove the quotes in my subquery. What are my possibilities to solve this problem?

Looking forward!

Raymond

Edit: in this case, i noticed $this->db->query will not work in the subquery.
#2

[eluser]JoostV[/eluser]
Code:
$this->db->select('f.price', false);
#3

[eluser]Raymondddd[/eluser]
Hmm many thanks Joost. Think that simple thing is all i need! Wink
#4

[eluser]JoostV[/eluser]
Well, you're not alone. That one has cost us all many headaches Smile




Theme © iAndrew 2016 - Forum software by © MyBB