【问题标题】:select one record each from two table. update the one value by matching the another one to a new table从两个表中选择一个记录。通过将另一个值匹配到新表来更新一个值
【发布时间】:2014-02-16 08:41:25
【问题描述】:

我有三个表,例如 table1,table2,table3..

我需要一个 mysql 解决方案。

table1,table2 中选择 table1.val1,table2.val1 并更新返回的值,如..

更新 table3 设置 value=table1.val1 where value=table2.val1

我的查询不起作用..

update db1.proprietor_profile_tbl as c3 set c3.PPROFILE_profileid=(select c2.COM_id from db2.company_profile_tbl as c1,db1.company_profile_tbl as c2 where c1.COM_name=c2.COM_name and COM_profiletype!=4) where c3.PPROFILE_profileid=c1.COM_id

“where 子句”中的未知列“c1.COM_id”

【问题讨论】:

  • table1和table2是什么关系?

标签: php mysql sql


【解决方案1】:
UPDATE  table3 t3
        INNER JOIN table2 t2
            ON t3.pcomid = t2.comid
        INNER JOIN table1 t1
            ON t1.name=t2.name
SET     t3.pcomid = t1.comid

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-23
    • 2012-08-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多