简体   繁体   English

如何用另一个表的关系更新列值

[英]How to update column values with relation of another table

How to add sub_cat_list.child_id dynamically from main_cat_list.id using php. 如何使用php从main_cat_list.id动态添加sub_cat_list.child_id。 below are 2 images of my parent and child table 以下是我的父母和孩子的桌子的2张图片

在此处输入图片说明

在此处输入图片说明

How to add values into sub_cat_list.child_id relative to sub_cat_list=rel_main_cat using php 如何使用php将值添加到相对于sub_cat_list = rel_main_cat的sub_cat_list.child_id中

Why do you want to use php? 为什么要使用php? It is possible with one query(if I correctly understood your question). 一个查询(如果我正确理解您的问题)是可能的。

UPDATE sub_cat_list sub
 INNER JOIN main_cat_list main ON main.main_cat_name = sub.rel_main_cat
   SET child_id = main.id

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM