MYSQL错误地使用UPDATE和ORDER BY RAND

时间:2016-12-03 09:39:07

标签: mysql

我正在尝试使用JOIN和RAND

进行更新
UPDATE table1 a INNER JOIN table2 b USING(id) 
SET a.description = CONCAT('different words', b.name)
WHERE a.description LIKE ''
ORDER BY RAND() LIMIT 100;

我收到错误:UPDATE和ORDER BY的使用不正确

没有加入以下代码完美无缺

UPDATE table1 SET description = CONCAT('different words', name) 
WHERE description LIKE ''
ORDER BY RAND() LIMIT 100;

感谢您的帮助

2 个答案:

答案 0 :(得分:0)

假设您正在使用String BId = "button1"; // for example int id = getResources().getIdentifier(BId, "id", getPackageName()); // finds R.id.button1 bdatum0 = (Button) findViewById(id); ,您应该将您的查询(使用用户变量和order by)包装为内联视图(MySQL将其称为派生表)。在UPDATE语句中将整个视图引用为行源。所以你的查询应该是这样的:

mysql

答案 1 :(得分:0)

试试这个:

 UPDATE a
 SET a.description = CONCAT('different words', b.name)
 FROM table1 a 
 INNER JOIN table2 b ON a.id=b.id 
 WHERE a.description LIKE ''
 ORDER BY RAND() LIMIT 100;