In MySQL server, I have 3 tables called user, thing, thingfile
user uid, username, name, location, version thing thingid, username,, version thingfile thingid, code, version
Each user has many things and each thing has many thingfiles.
I am going to delete from user table like below:
delete FROM user a WHERE a.username NOT IN (
SELECT b.by_user
FROM bp_userlist b)
and a.version="823"
Updated: before delete: user:
uid username name location version
1 abc abc abcdd O
2 abc abc abcdd 823
3 ddd ddd dddd 823
thing
thingid username version
1 abc O
2 abc O
1 abc 823
2 abc 823
3 ddd 823
1 ddd 823
thingfile
thingid code version
1 ee O
2 eed O
1 ee 823
2 eddd 823
3 fff 823
after delete: user:
uid username name location version
1 abc abc abcdd O
3 ddd ddd dddd 823
thing
thingid username version
1 abc O
2 abc O
3 ddd 823
1 ddd 823
thingfile
thingid code version
1 ee O
2 eed O
3 fff 823
I want those records belonging to thingid in thing and thingfile tables be deleted as well. Is it possible without foreign key constrains?I have more than 10 tables and so many join doesnt work in one query.