How do you DELETE rows in a mysql table that have a field IN the results of another query?
- by user354825
here's what the statement looks like:
DELETE FROM videoswatched vw2
WHERE vw2.userID IN ( SELECT vw.userID
FROM videoswatched vw
JOIN users u ON vw.userID=u.userID
WHERE u.companyID = 1000
GROUP BY userID )
that looks decent to me, and the SELECT statement works on its own (producing rows with a single column 'userID'.
basically, i want to delete entries in the 'videoswatched' table where the userID in the videoswatched entry, after joining to the users table, is found to have companyID=1000.
how can i do this without getting the error in my sql syntax? it says the error is near:
vw2 WHERE vw2.userID IN (
SELECT vw.userID FROM videoswatched vw
JOIN users u
and on line 1. thanks!