I need to delete from two tables, based on a query in one table
Table: entities
guid: integer
subtype: integer
time_created: integer (Unix timestamp)
Table: objects_entity
guid: integer
title: text
guid in objects_entity is a foreign key to entities.guid
I need to delete related records in both tables based on subtype=17 and time_created is older than 14 days in entities (so also delete related objects_entity)
I’m very bad at SQL and by looking at examples I’ve created this:
DELETE entities, objects_entity FROM entities a INNER JOIN objects_entity b on b.guid = a.guid AND a.subtype =17 AND a.time_created < UNIX_TIMESTAMP(DATE_SUB(NOW(), INTERVAL 14 DAY))
but this gives the error:
#1109 - Unknown table 'entities' in MULTI DELETE
which is beyond me, as a select statement identical to above works correctly…. The table exists.
Any ideas what’s wrong with my syntax? Many thanks.
You need to replace
with
since you are aliasing your tables with
aandb.