如果其他数据库中不存在,我需要根据该数据库从一个数据库中清除记录。
很难解释,所以这里是例子:
Table Users
-----------
id
username
password
Table Articles
--------------
id
title
created_by
edited_by
created_by
并deleted_by
包含用户 ID。我有 3-4 个表,其结构几乎与文章表相同,我想从表用户中删除在文章表中没有任何记录的用户。我的意思是在and表
中的任何类似文章的表中都找不到 ID 的用户。
怎么做?
我先试了下是否可以根据用户选择所有表的所有数据,但是服务器无法执行查询:created_by
edited_by
SELECT * FROM `users`
JOIN `articles`
ON `articles`.`created_by` = `users`.`id`
AND `articles`.`edited_by` = `users`.`id`
JOIN `articles_two`
ON `articles_two`.`created_by` = `users`.`id`
AND `articles_two`.`edited_by` = `users`.`id`
JOIN `articles_three`
ON `articles_three`.`created_by` = `users`.`id`
AND `articles_three`.`edited_by` = `users`.`id`
JOIN `articles_four`
ON `articles_four`.`created_by` = `users`.`id`
AND `articles_four`.`edited_by` = `users`.`id`
JOIN `articles_five`
ON `articles_five`.`created_by` = `users`.`id`
AND `articles_five`.`edited_by` = `users`.`id`
JOIN `articles_six`
ON `articles_six`.`created_by` = `users`.`id`
AND `articles_six`.`edited_by` = `users`.`id`;