首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >update语句with limit

update语句with limit
EN

Stack Overflow用户
提问于 2015-07-22 02:30:05
回答 2查看 678关注 0票数 0
代码语言:javascript
复制
update accounts a
left join users b on
    a.user_id = b.user_id
set `sold` = '1' where b.country = 'UA' AND a.site = 'od'

如何限制此查询?

已尝试

代码语言:javascript
复制
update accounts a
left join users b on
    a.user_id = b.user_id
set `sold` = '1' where b.country = 'UA' AND a.site = 'od' LIMIT 500

但get错误错误: UPDATE和LIMIT的用法不正确

EN

回答 2

Stack Overflow用户

发布于 2015-07-22 02:45:08

尝尝这个

代码语言:javascript
复制
update accounts a left join users b on a.user_id = b.user_id
set 'sold' = '1'
where b.country in
(select country from
(select country from users where
country = 'UA' order by user_id asc limit 500) tmp) and 
a.site in
(select site from
(select site from accounts where
site = 'od' order by user_id asc limit 500) tmp2);

有关select limit语句的详细信息,请参阅此部分。

http://www.techonthenet.com/sql/select_limit.php

票数 0
EN

Stack Overflow用户

发布于 2015-07-22 03:38:34

我将首先使用一个CTE表(临时表)来保存您的限制查询,然后使用该表执行更新:

代码语言:javascript
复制
With LimitQuery As
(
select * from  accounts a
left join users b on
    a.user_id = b.user_id
where b.country = 'UA' AND a.site = 'od' LIMIT 500
)

update LimitQuery 
set `sold` = '1' 
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/31546922

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档