如何将数据更新到由MYSQL中的查询生成的表中

时间:2013-02-07 20:09:39

标签: mysql sql

我在这里查询此表

SELECT
  a.ESN,
  b.URL,
  a.Status,
  a.GroupID,
  a.RouteID
FROM STx a
  LEFT JOIN Routes b
    ON a.RouteID = b.RouteID
WHERE a.GroupID = 39
    AND a.Status = "Provisioned"
order by a.ESN;

现在从结果集中,我想将路由网址修改为测试,以便修改所有行第一个查询结果中的 url 列。如何在查询中执行此操作?

2 个答案:

答案 0 :(得分:0)

update Routes set url = 'test' 
where id in (
    select b.id 
    from Stx a left join routes b on a.routeid = b.routeid 
    where a.groupid = 39 and a.status = 'Provisioned'
);

答案 1 :(得分:0)

如果我正确理解您的问题,您希望将URL列更新为“测试”,以获取从原始查询中获得的所有结果。

UPDATE Routes
SET URL = 'Test'
FROM STx AS A
LEFT JOIN Routes AS B
ON a.RouteID = b.RouteID
WHERE a.GroupID = 39 AND a.Status = 'Provisioned'