How do you DELETE rows in a mysql table that have a field IN the results of another query?
Posted
by user354825
on Stack Overflow
See other posts from Stack Overflow
or by user354825
Published on 2010-05-31T19:00:30Z
Indexed on
2010/05/31
19:33 UTC
Read the original article
Hit count: 177
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!
© Stack Overflow or respective owner