I have not managed to find an example of this. Maybe it's impossible, or I am just not using proper search words.
It's simple: I have a joined table with Foreign keys for events:
CREATE TABLE dbp_Join(
Event INT,
Participant INT,
Location INT,
TST TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
ON UPDATE CURRENT_TIMESTAMP,
FOREIGN KEY(Event) REFERENCES dbp_Events(ID)
ON UPDATE CASCADE
ON DELETE CASCADE,
FOREIGN KEY(Participant) REFERENCES dbp_Participants(ID)
ON UPDATE CASCADE
ON DELETE CASCADE,
FOREIGN KEY(Location) REFERENCES dbp_Locations(ID)
ON UPDATE CASCADE
ON DELETE CASCADE
)ENGINE = INNODB;
And I have events table:
CREATE TABLE dbp_Events(
ID INT auto_increment,
Name Char(80),
ETime DATETIME NOT NULL,
Details VARCHAR(2000),
E_TST TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY(ID, E_TST)
)ENGINE = INNODB;
I have values in the Join table that reference the events and users attending them. I want to delete all rows in Join table that reference the event happening on 2014-12-12. How do I write that query? Can I? I want to have something like this:
DELETE FROM dpb_Join WHERE DATE(dbp_Events.`ETime`)='2014-12-12';
I have tried
DELETE FROM dbp_Join, dbp_Events WHERE DATE(`ETime`)='2014-12-12';
but it doesn't work, it just empties the whole table.
UPDATE: Tried an example from MySQL DELETE reference that seemed like the right way to do it, but it doesn't delete anything:
DELETE dbp_join FROM dbp_join INNER JOIN dbp_events
WHERE DATE(dbp_events.ETime='2014-12-12');