dsy1971 2012-02-28 17:27
浏览 48

MySQL更新一个表,但使用来自其他两个表的数据作为更新的一部分

I wish to update one table in my database, the data is from a php POST. (It is a page where multiple edits on rows can take place at once, then it processes them all at once after) and i want it so for each "row" or "loop", it builds a single query that can update all the rows at once.

What i want to do, is in the query, select data from two other tables. E.g

Posted data:
 - Task = "Check current Sponsors"
 - User Assigned = "Dan"
 - Start Meeting = "Mar 1st"
 - Meetings Required = 2

And for User Assigned, i want it to basically do this query:

SELECT id FROM team WHERE fullname LIKE 'Dan'

And for the start meeting, i want it to do this query:

SELECT id FROM meetings WHERE starttime='".strtotime("Mar 1st")."'

-- strtotime() makes a unix timestamp from a string.

but i want it to do that for each "task" that gets submitted. (It is queued up via javascript and it sends them all into the same post request)

Anyone have any ideas on how to do this? Thanks in advance

Table Structures:

Tasks:

id | startmid | length | task           | uid | completed
1  | 2        | 1      | Check Sponsors | 1   | 0

Meetings: (Joined by startmid)

id | maintask | starttime  | endtime
1  | Sponsors | 1330007400 | 1330012800

Team: (Joined by uid)

id | fullname | position     | class | hidden
1  | Team     | All Members  | black | 0
2  | Dan S    | Team Manager | green | 0
  • 写回答

1条回答 默认 最新

  • doxp30826 2012-02-28 17:31
    关注

    you can use the following construct:

    UPDATE mytable( col1, col2 )
    SELECT col1_val, col2_val
    FROM someothertables
    WHERE cond1 = cond1;
    
    评论

报告相同问题?

悬赏问题

  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看