Welcome Guest, Not a member yet? Register   Sign In
Update two tables with each others values
#1

[eluser]Unknown[/eluser]
Hi, there.

I have a question.

I want to run a simple query like this one:

update table_1 t1, table_2 t2 set t1.field = t2.field where t1.id_something = t2.id

As you can see, I want to update some values at table_1 using table_2's values.

I tried at CI something like this:

$this->db->set('t1.field = t2.field');
$this->db->where('t1.id_something = t2.id');
$this->db->update('table_1 t1, table_2 t2');

The problem is at the first line, with the set function. It expects a value as a second parameter and I can't run the query.

I'm avoiding the trivial solution that would be $this->db->query('update table_t1....') for obvious reasons.

Any ideas?

Thanks everyone!




Theme © iAndrew 2016 - Forum software by © MyBB