sql查询从table1中选择id并更新到table2

时间:2015-04-04 15:28:03

标签: php mysql

我有两张桌子好

  hawker_master table
  id   hawker_name
  1     raj
  2     vicky

  customer_entry table
  hawkername
   raj
   raj
   vicky

我需要从hawkermaster中选择特定hawker_name的id的sql查询,并在customer_entry表中更新id代替hawkername,如下所示..

FOR EX -

  customer_entry table
  hawkername
   1
   1
   2

1 个答案:

答案 0 :(得分:0)

您可以使用多表UPDATE语法来执行连接:

UPDATE customer_entry ce
  JOIN hawker_master  hm ON hm.hawker_name = ce.hawkername
SET    ce.hawkername = hm.id