mysql-关于选择查询的更新查询[重复]

时间:2022-05-20 21:46:03

This question already has an answer here:

这个问题在这里已有答案:

hi here i have two tables named as test and test2.

在这里,我有两个名为test和test2的表。

test is as follows

测试如下

mysql-关于选择查询的更新查询[重复]

test2 is as follows

test2如下

mysql-关于选择查询的更新查询[重复]

i am using below sql code to get the below output.

我使用下面的SQL代码来获得以下输出。

UPDATE `test`
SET `availability` = 'ok'
WHERE
    `id` = '(SELECT
test.id
FROM
test2
INNER JOIN test ON test.id = test2.PId)';

I requires below output. but it outcomes no any output. kindly help. any mistakes done by my end or if there is any best mothod to get below output, kindly mention

我要求低于输出。但它没有产生任何结果。善意的帮助。请注意,如果我的结果有任何错误,或者有任何最好的方法可以获得低于产量的话

mysql-关于选择查询的更新查询[重复]

3 个解决方案

#1


1  

I think you're looking for something along the lines of

我想你正在寻找类似的东西

UPDATE test 
INNER JOIN test2 on test.id = test2.PId
SET test.availability = 'OK'

#2


0  

Sounds like you don't need an update, just a query with a join:

听起来你不需要更新,只需要一个带连接的查询:

SELECT test.id, test.name, CASE WHEN teste2.pid IS NOT NULL THEN 'OK' END
FROM   test
JOIN   test2 ON test.id = test2.pid

#3


0  

I am not sure if this will work.but hey we all try here right..

我不确定这是否有用。但是,我们都在这里试试..

UPDATE `test`
SET `availability` = 'ok'
WHERE
`id` in '(SELECT
PId from test2)';

I don't get , why do you need inner join.You only need those id's that are present in test2 table,then just take it. although i have used 'in' keyword,try with '=' also but i doubt it will work because inner query is returning a list of id's.thanks.

我不明白,为什么你需要内部联接。你只需要那些在test2表中出现的id,然后只需要它。虽然我使用'in'关键字,但尝试使用'=',但我怀疑它会起作用,因为内部查询返回ids.thanks列表。

#1


1  

I think you're looking for something along the lines of

我想你正在寻找类似的东西

UPDATE test 
INNER JOIN test2 on test.id = test2.PId
SET test.availability = 'OK'

#2


0  

Sounds like you don't need an update, just a query with a join:

听起来你不需要更新,只需要一个带连接的查询:

SELECT test.id, test.name, CASE WHEN teste2.pid IS NOT NULL THEN 'OK' END
FROM   test
JOIN   test2 ON test.id = test2.pid

#3


0  

I am not sure if this will work.but hey we all try here right..

我不确定这是否有用。但是,我们都在这里试试..

UPDATE `test`
SET `availability` = 'ok'
WHERE
`id` in '(SELECT
PId from test2)';

I don't get , why do you need inner join.You only need those id's that are present in test2 table,then just take it. although i have used 'in' keyword,try with '=' also but i doubt it will work because inner query is returning a list of id's.thanks.

我不明白,为什么你需要内部联接。你只需要那些在test2表中出现的id,然后只需要它。虽然我使用'in'关键字,但尝试使用'=',但我怀疑它会起作用,因为内部查询返回ids.thanks列表。