请各位高手帮忙:
假如我有两张及字段如下:
a topic_id ,topic_name ....
b post_id ,topic_id....
我的sql语句如下:
sql=delete from a topic_id not in(select * from b) where topic_id=1;
这样对吗?我的意思是:删除a表,如果a表的id在b表中存在,就不删除,请各位高手指点!
假如我有两张及字段如下:
a topic_id ,topic_name ....
b post_id ,topic_id....
我的sql语句如下:
sql=delete from a topic_id not in(select * from b) where topic_id=1;
这样对吗?我的意思是:删除a表,如果a表的id在b表中存在,就不删除,请各位高手指点!
delte a from a left join b using(topic_id) where b.topic_id is null
delete from a where not exists (select 1 from b where topic_id=a.topic_id);
where A.topic_id=1 AND b.topic_id is null
同意一楼!
delete from a where topic_id not in (select topic_id from b);这个正解~~~~