从具有连接的两个表中删除? [英] Delete from two tables with join?

查看:81
本文介绍了从具有连接的两个表中删除?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个表格如下

tbl1              tbl2
id                article_id
title,            image
whole_news
tags,
author,
older (datetime)

其中tbl1.id-> tbl2.article_id

where tbl1.id -> tbl2.article_id

如何从两个旧表<中删除表中的记录2008-02-10 00:00:00吗?

How to delete records from both tables where older is < 2008-02-10 00:00:00 ?

推荐答案

请参阅我对类似问题的回答

See my answer to a similar question here.

总而言之,它看起来像

 delete s, r from tbl1 s left join tbl2 r on s.id = r.article_id where s.older < str_to_date('2008-02-10 00:00:00', '%Y-%m-%d %H:%i:%S');

但是更好的解决方案是使用on删除级联的外键约束,如果这是一个选项,则只需使用适当的where子句从tbl1中删除.

But the better solution would be a foreign key constraint with an on delete cascade, if that is an option, then just delete from tbl1 with the appropriate where clause.

这篇关于从具有连接的两个表中删除?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆