Cómo hacer 3 tabla UNIRSE en la consulta de ACTUALIZACIÓN?
Hice una pregunta y recibí esta respuesta que me ayudó.
UPDATE TABLE_A a JOIN TABLE_B b
ON a.join_col = b.join_col AND a.column_a = b.column_b
SET a.column_c = a.column_c + 1
Ahora estoy buscando hacer esto si hay 3 tablas involucradas algo como esto.
UPDATE tableC c JOIN tableB b JOIN tableA a
Mi pregunta es, básicamente... ¿es posible hacer 3 table join en una instrucción UPDATE
? ¿y cuál es la sintaxis correcta para ello? Agradecer. Yo hago el...
JOIN tableB, tableA
JOIN tableB JOIN tableA
5 answers
La respuesta es yes
puedes
Inténtalo así
UPDATE TABLE_A a
JOIN TABLE_B b ON a.join_col = b.join_col AND a.column_a = b.column_b
JOIN TABLE_C c ON [condition]
SET a.column_c = a.column_c + 1
EDITAR:
Para la Actualización general únete:
UPDATE TABLEA a
JOIN TABLEB b ON a.join_colA = b.join_colB
SET a.columnToUpdate = [something]
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-09-16 08:47:11
La forma alternativa de lograr el mismo resultado es no usar la palabra clave JOIN
en absoluto.
UPDATE TABLE_A, TABLE_B
SET TABLE_A.column_c = TABLE_B.column_c + 1
WHERE TABLE_A.join_col = TABLE_B.join_col
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-06-23 08:32:52
A continuación se muestra la consulta de actualización que incluye JOIN
& WHERE
ambos. De la misma manera que podemos usar la cláusula multiple join/where, espero que te ayude: -
UPDATE opportunities_cstm oc JOIN opportunities o ON oc.id_c = o.id
SET oc.forecast_stage_c = 'APX'
WHERE o.deleted = 0
AND o.sales_stage IN('ABC','PQR','XYZ')
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-06-19 15:03:18
Un Plan General alternativo, que solo estoy agregando como una Respuesta independiente porque el maldito "comentario sobre una respuesta" no tomará nuevas líneas sin publicar toda la edición, a pesar de que aún no está terminado.
UPDATE table A
JOIN table B ON {join fields}
JOIN table C ON {join fields}
JOIN {as many tables as you need}
SET A.column = {expression}
Ejemplo:
UPDATE person P
JOIN address A ON P.home_address_id = A.id
JOIN city C ON A.city_id = C.id
SET P.home_zip = C.zipcode;
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-05-31 17:18:07
Para PostgreSQL ejemplo:
UPDATE TableA AS a
SET param_from_table_a=FALSE -- param FROM TableA
FROM TableB AS b
WHERE b.id=a.param_id AND a.amount <> 0;
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-12-28 08:24:43