使用表连接删除问题

2019-03-25 13:37|来源: 网路

现有表
test
------------------
a(主键) b
1      aaaa
2      bbbb

test1
------------------
a1(主键) a     b1
1         1    aaaa
2         2    bbbb
3         3    cccc

delete (select a.a,a.b from test a,test1 b where a.a != b.a );
删除两个表未关联的数据

问题补充:
额。。需求是不用exists和in来实现。。不然的话我也不会用表连接勒

问题补充:
现有表
test
------------------
a(主键) b
1      aaaa
2      bbbb

test1
------------------
a1(主键) a     b1
1         1    aaaa
2         2    bbbb
3         3    cccc

delete (select a.a,a.b from test a,test1 b where a.a != b.a );
删除两个表未关联的数据

问题补充:
额。。需求是不用exists和in来实现。。不然的话我也不会用表连接勒

相关问答

更多
  • 你的映射是错误的。 在Component中,您说组件和任务之间的关联由连接表映射。 在Task中,您说同一个关联是由Task表中的连接列映射的。 下定决心。 如果关联是OneToMany双向关联,则通常不需要连接表,您只需要 @OneToMany(cascade = CascadeType.ALL, mappedBy = "component") public List getTasks() { return tasks; } 和 @ManyToOne @JoinColumn(name ...
  • 从用户权限列表中删除权限,然后保存用户对象。 如果正确配置了级联,则应从连接表中删除相应的条目。 Delete the permission from the list of permissions of the user and then save the user object. If the cascade is configured correctly that should delete the respective entry from the join table.
  • 破坏笔记后,您可以销毁孤立标签。 def destroy @note = Note.find_by(id: params[:id]) if @note @note.destroy_with_tags end end def destroy_with_tags oldtag_ids = tag_ids destroy Tag.find(oldtag_ids).each do |tag| tag.destroy if tag.notes == [] end end ...
  • 由于您有一个连接表,标签表本身没有post_id,因此find_by不起作用。 但是不需要它,因为post.tags无论如何都会检索连接到该帖子的所有标签。 使用诸如collection_check_boxes之类的东西,你可以获得很多处理habtm关系和表单的功能,我不认为你需要额外的destroy标签方法,除非我误解你想要完成的事情。 您可以考虑在帖子中添加/删除标签关联,如下所示: 发布 - has_and_belongs_to_many:标签 标签 - has_and_belongs_to_many ...
  • 为每个表提供一个别名,并在DELETE一词后面引用它。 此外,使用LEFT JOIN而不是INNER JOIN因为我猜你仍然希望删除工作事件,如果某些连接表没有匹配的行。 db_delete->prepare("DELETE bp, i, f, p, r, v FROM blog_post AS bp LEFT JOIN ipaddress_likes_map AS i ON i.postat = bp.BID LEFT JOIN flagpost AS f ON f.postId = bp.BID LEF ...
  • 我想你可能想用一个has many through这里 假设类似于: class CustomerOrders belongs_to :customer belongs_to :order end class Customer has_many :customer_orders has_many :orders, through: :customer_orders end 这样你就可以得到实际的订单和连接,并分别处理两者。 在你的例子中,什么是Order是Order或者Custom ...
  • 您对多对多关系如何运作的理解是完全错误的。 让我们举个例子: class Patient < ApplicationRecord has_many :appointments, dependent: :destroy has_many :doctors, through: :appointments end class Appointment < ApplicationRecord belongs_to :patient belongs_to :doctor end class Doct ...
  • 似乎只在连接表上使用实体ID来修复它。 不知道为什么不能引用外键,但它有效! 无论如何,这是一个更好的设计,因为id不能改变。 It appears that using only entity id's on the join table fixed it. Not sure why there can't be references to foreign keys, but it works! It's a better design anyways since id's cannot be alter ...
  • 所以你可能已经发现,删除效率不高。 如果你有磁盘空间,我建议你只根据内连接(你想要的记录)创建一个新表,drop table1,并重命名结果table1。 %let n=1000000; data table1; do rowid=1 to &n; value = rowid**2; output; end; run; data table2; do rowid=1 to &n; value = (mod(rowid,2)=1)*rowid**2; output; end ...
  • 你的代码说要破坏课程,这就是ActiveRecord正在做的事情。 您想要删除关联,而不是破坏用户或课程。 解决方案是使用collection.delete(object, …) 这将通过从连接表中删除关联来从集合中删除每个对象。 这不会破坏对象。 示例代码: def delete_user_course_association(user_id, course_id) user = User.find(user_id) course = user.courses.find(course_id) ...