1

I need to update my database its a soft delete on multiple row based in locationId

update device d
set d.deleteDate='2016-05-07'
where d.id in (select dtg.deviceId from devicestogroups dtg
               where dtg.groupId in (select g.id from `group` g
                                     where g.locationId ='1'));

When I run the query I get the error:

Error Code: 1175. You are using safe update mode and you tried to update a table without a WHERE that uses a KEY column To disable safe mode, toggle the option in Preferences -> SQL Editor and reconnect.

Subquery will return me 2 records as I know because subquery returns two record update will not happen, but how do I solve this issue. I tried to solve but not successful.

3 Answers 3

2

Try this, it would more better to use join instead of sub query with IN:

UPDATE device d
INNER JOIN devicestogroups dtg ON dtg.deviceId = d.id
INNER JOIN `group` g ON g.id = dtg.groupId
    AND g.locationId ='1'
SET d.deleteDate='2016-05-07'

OR

UPDATE device d
INNER JOIN devicestogroups dtg ON dtg.deviceId = d.id
INNER JOIN `group` g ON g.id = dtg.groupId
SET d.deleteDate='2016-05-07'
WHERE g.locationId ='1'
Sign up to request clarification or add additional context in comments.

Comments

0

try this:

update device set deleteDate='2016-05-07' 
where id in (select dtg.deviceId from devicestogroups dtg where dtg.groupId in ( select g.id from `group` g where g.locationId ='1'));

if you execute update not using alias on column to update

1 Comment

Thanks for your response but still the query fail to update for same reason
0

Try this:

update d
set d.deleteDate='2016-05-07'
from device d
inner join devicestogroups dtg on d.id=dtg.deviceId
inner join `group` g on g.id =dtg.groupId
where g.locationId ='1'

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.