CodeIgniter Forums
Using Database Class to perform updates, combining 2 tables - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: Using Database Class to perform updates, combining 2 tables (/thread-47627.html)



Using Database Class to perform updates, combining 2 tables - El Forum - 12-15-2011

[eluser]mallix[/eluser]
Hello everybody,

I have an sql query like this:

Lets say we have 2 tables: a USER and a USER_PROFILE
We want to update the USER_PROFILE table row: surname,name,city etc via USER id .
Relationship is 1 USER row has 1 PROFILE row, so table USER has a profile_id in it.
a normal query would be:

Code:
UPDATE user_profile
set surname=value,name=value,city=value
where user_profile.id IN
(SELECT user.profile_id
FROM user
WHERE user.id = value)

Can we implement this using codeIgniter s database class?
Updating 1 table s values when we have another s table known key and both tables are related.