I am in the same case discussed on https://stackoverflow.com/questions/11709043/mysql-update-column-with-value-from-another-table, that is, I need to copy the value of a column from tableA to tableB based on a common column in each table.
I have used the suggested code inside of PHPMyAdmin, and it works perfectly:
UPDATE TableB
SET TableB.value = (
SELECT TableA.value
FROM TableA
WHERE TableA.name = TableB.name
);
My problem is that I have been unable to translate this into something that I can use inside of my mod_xxx.php
file. On the same Stack Overflow page, there is a suggested code that uses mysql_query
and supposedly works, but Joomla doesn´t accept it. I know that any code has to be translated to Joomla's coding standards but I have spent three complete days trying it with no success.
I have tried the following code unsuccessfully:
$db = JFactory::getDBO();
$query = $db->getQuery(true);
$query ->UPDATE ('#__gruposlocales')
->SET ('#__gruposlocales.name') =
(SELECT ('#__community_groups.name')
FROM ('#__community_groups')
WHERE ('#__community_groups.ownerid = #__gruposlocales.id'));
$db->setQuery($query);
$result = $db->execute();
As you may guess, I am not knowledgeable on PHP coding, so I am in serious need of your help, please. My question is how can I translate the upper code into something that Joomla will take?