Mysql SQL更新查询
我的数据库中有40000行需要更新。但是,我使用的select查询跨越两个表 下面是我的选择查询的示例:Mysql SQL更新查询,mysql,sql,Mysql,Sql,我的数据库中有40000行需要更新。但是,我使用的select查询跨越两个表 下面是我的选择查询的示例: select t1.*, t2.data, t2.more_data, t2.more_data2 from table1 as t1, table2 as t2 where DATE(t1.date) >= '2014-10-23' and t1.direction = 10 and t1.date_read is NULL and t1.fk_client is NULL an
select t1.*, t2.data, t2.more_data, t2.more_data2
from table1 as t1, table2 as t2
where
DATE(t1.date) >= '2014-10-23'
and
t1.direction = 10
and
t1.date_read is NULL
and
t1.fk_client is NULL
and
t1.id=t2.id
and
t2.data = 'this is dummy text';
我一直在查看其他人对这方面的要求,但我似乎无法理解
编辑:
我想做的是用
2015-03-17 09:00:00
更新t1.date\u read
,其中t2.data
等于“这是虚拟测试”
首先,您的查询中有一些错误
t1*
缺少点->t1.*
t3.更多数据2
-t3未在查询中衰减t2.data='这是虚拟文本代码>错过关闭报价
SELECT
t1.*,
t2.data,
t2.more_data
FROM
table1 as t1,
INNER JOIN
(SELECT *
FROM table2
WHERE
data = 'this is dummy text'
) as t2
ON
t1.id=t2.id
WHERE
DATE(t1.date) >= '2014-10-23
AND
t1.direction = 10
AND
t1.date_read is NULL
AND
t1.fk_client is NULL
我想做的是用2015-03-17 09:00:00
更新t1.date\u read
,其中t2.data
等于“这是虚拟测试”
只需在更新的WHERE
子句中插入对另一个表的引用,如下所示:
UPDATE table1
SET date_read = '2015-03-17 09:00:00'
where table1.id IN (SELECT id from table1 as t1
INNER JOIN table2 as t2 ON t1.id=t2.id
WHERE t2.data = 'this is dummy test')
如果您想在问题中包含您键入的其他参数,只需在末尾添加它们
--[code from above]
AND
DATE(table1.date) >= '2014-10-23'
AND
table1.direction = 10
AND
table1.date_read is NULL
AND
table1.fk_client is NULL
您要更新哪些列以及哪些值?那么您的问题是什么?您的
t3查询中没有声明t3
表。更多数据2
我可以看到您的查询存在多个问题。。。SELECT
中缺少
,日期和数据字段上缺少结束引号,缺少表引用(t3),名为date的列的异常date
强制转换,使用已被弃用20多年的JOIN
语法。。。但您的问题到底是什么?字符串以单引号开始,但结尾引号不存在