Home >Backend Development >PHP Tutorial >求助 sql语句
有两张数据表:
第一张有2个字段 id 和 name1,第二张表有3个id p_id name2,第二张表的p_id是第一张表的外键。怎么修改使第二张表的name2的值为:name1/name2.
比如第一张表数据:id 1
name one
第二张表数据: id 1
p_id 1
name1 two
怎么修改使第二张表数据为: id 1
p_id 1
name2 one/two
我用这样sql语句没反应:
"update two,one set two.name2=two.name2."/".one.name1 where two.p_id=one.id"
可以先查询出来
select two.name2 as s,one.name1 as f,p_id as myid from two,one where two.p_id=one.id;
$res = f/s;
update two set name2=$res where p_id = myid;
这3条怎么用啊?我mysql菜鸟。
update two inner join one set two.name2=one.name1/two.name2 on two.p_id=one.id
update two inner join one set two.name2=one.name1/two.name2 on two.p_id=one.id
运行没反映啊。
update two join one on two.p_id=one.id set name2= concat(name2,'/',name1)
谢谢,成功了。
$sql="update two,one set two.name=concat(one.name,'/',two.name) where one.id=two.p_id";刚才试了下,这样也可以。要用到concat这个函数。