开发者

SQL: Update Table

开发者 https://www.devze.com 2023-03-16 08:02 出处:网络
i have got 3 tables: Event, task, task_handler. EVENT: event_id|name TASK_HANDLER: event_id|task_seq|handler

i have got 3 tables: Event, task, task_handler.

EVENT:
event_id|name

TASK_HANDLER:
event_id|task_seq|handler

TASK:
event_id|task_seq|script

what i want is that "script" has the same content as "name". task_handler.handler is event.event_id.

So what i have to do is get the event.name for each event_开发者_Go百科id/task_seq combination an put it into task.script.

Result should like this: http://imageshack.us/photo/my-images/825/stackover.jpg/


I'm not sure if I understood your relationships (I'm confused by handler being the event_id) but try this:

UPDATE `TASK` t
INNER JOIN `TASK_HANDLER` th ON th.event_id = t.event_id AND th.task_seq = t.task_seq
INNER JOIN `EVENT` e ON e.event_id = th.handler
SET t.script = e.name


Use this query.

SELECT
  e.event_id,t.task_seq,a.name as 'script'
FROM
  EVENT e, TASK_HANDLER t
WHERE
  e.event_id = t.event_id
0

精彩评论

暂无评论...
验证码 换一张
取 消