MySQL UPDATE query based on SELECT Query —
You can do this in different forms(6 in my example) :
1: (IN)
UPDATE tbl_category_mark_model_form tbl_1 SET tbl_1.token=NULL WHERE tbl_1.id IN (
SELECT * FROM (
SELECT id FROM tbl_category_mark_model_form
) t
);
2: (NOT IN)
UPDATE tbl_category_mark_model_form tbl_1 SET tbl_1.token=NULL WHERE tbl_1.id NOT IN (
SELECT * FROM (
SELECT id FROM tbl_category_mark_model_form
) t
);
3: (SUB QUERY)
UPDATE tbl_category_mark_model_form AS tbl_1
INNER JOIN (
SELECT * FROM tbl_category_mark_model_form
) AS tbl_2 ON tbl_1.id = tbl_2.id
SET tbl_1.token = CONCAT_WS(':', tbl_2.category_id, tbl_2.form_id, tbl_2.mark_id, tbl_2.model_id)
;
4: (LEFT JOIN)
UPDATE tbl_category_mark_model_form tbl_1
LEFT JOIN tbl_category_mark_model_form tbl_2 ON
tbl_1.id = tbl_2.id
SET
tbl_2.token = CONCAT_WS(':', tbl_1.category_id, tbl_1.form_id, tbl_1.mark_id, tbl_1.model_id)
;
5: (INNER JOIN)
UPDATE
tbl_category_mark_model_form tbl1
INNER JOIN
tbl_category_mark_model_form tbl2
ON
tbl1.id = tbl2.id
SET
tbl2.token = CONCAT_WS(':', tbl1.category_id, tbl1.form_id, tbl1.mark_id, tbl1.model_id)
;
6: (NOT)
UPDATE tbl_category_mark_model_form tbl_1 SET tbl_1.token=NULL WHERE tbl_1.id NOT (
SELECT * FROM (
SELECT id FROM tbl_category_mark_model_form
) t
);
Categorised as: MySQL
Comments are disabled on this post