I have the followin query: SELECT DISTINCT (ip), page_id FROM `temp`) Code (mysql): It shows the the unique hits for every page. Now I want to delete all the rows that are not in the result of the query above. How do I do that? I've tried multiple things including the following, but that didn't work: DELETE FROM temp WHERE ip NOT IN(SELECT DISTINCT (ip), page_id FROM `temp`) Code (mysql):
What does 'didn't work' mean? Did it give you an error? Or didn't it delete anything? If it gives you an error, please tell us which one. If it doesn't delete anything, that's perfectly normal. Look closely at your query. What is says is: delete from the table 'temp' the ip's that aren't present in the same table 'temp'. Since the subquery selects all ip's present in the table (there is no WHERE clause), the WHERE clause of the delete will never be true, and nothing will be deleted.