Click here to Skip to main content
15,748,930 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
the thing is that i don know if there is a way to get a value from a subquery over an update operation, the query that i'm trying to do looks like this, on a example code of my model :

$query = "UPDATE some_table SET value_1 = ((SELECT value_2 FROM other_table WHERE id = 2) + 1) WHERE id = 2";


i hope you can help me or at least let me know an alternative way to get this using the active record

PD i'm working with the CodeIgniter Framework
Updated 23-Jul-14 12:26pm
Zeeshan17 30-Aug-14 12:38pm    
Sorry didn't understand what you need exactly,please be clear what you want to achieve so that i can help you.

1 solution

You can call a subQuery function where

((SELECT value_2 FROM other_table WHERE id = 2) + 1)

will be executed and be used on the same model.



Class Example_model Extends CI_Model
function subQuery()
$query = "SELECT value_2 FROM other_table WHERE id = 2;
$q = $this->db->query($query);
function mainQuery($subQuery)
$query = "UPDATE some_table SET value_1 = "'.$subQuery.'" WHERE id = 2";

If you want to use the active record(recommended) instead of queries. You can start translating your queries to active records by reading this one.
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900