Reputation: 13
I have two tables in a mysql database. macs and deviceinventory i want to updat macs table column name deviceid =1 but update those reords which not found in deviceinventory table column device id i use this query but it give error
UPDATE macs SET deviceid = 1
WHERE deviceid = (SELECT deviceid FROM macs NOT IN (
SELECT * FROM deviceinventory.`deviceid`
)) ;
Upvotes: 1
Views: 57
Reputation: 1099
try this:
UPDATE
macs
SET
deviceid = 1
WHERE
deviceid NOT IN
(SELECT deviceid FROM deviceinventory);
Upvotes: -1
Reputation: 94469
UPDATE macs
SET deviceid = 1
WHERE deviceid IN (
SELECT deviceid
FROM macs
WHERE deviceid NOT IN (
SELECT deviceid
FROM deviceinventory
)
) ;
Upvotes: 2